super-three 0.184.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/build/three.cjs +1260 -927
- package/build/three.core.js +1104 -829
- package/build/three.core.min.js +1 -1
- package/build/three.module.js +156 -98
- package/build/three.module.min.js +1 -1
- package/build/three.tsl.js +11 -4
- package/build/three.tsl.min.js +1 -1
- package/build/three.webgpu.js +7538 -3367
- package/build/three.webgpu.min.js +1 -1
- package/build/three.webgpu.nodes.js +7538 -3366
- package/build/three.webgpu.nodes.min.js +1 -1
- package/examples/jsm/Addons.js +3 -0
- package/examples/jsm/controls/ArcballControls.js +6 -2
- package/examples/jsm/controls/FirstPersonControls.js +79 -42
- package/examples/jsm/controls/TransformControls.js +68 -15
- package/examples/jsm/csm/CSMFrustum.js +31 -6
- package/examples/jsm/csm/CSMShadowNode.js +4 -1
- package/examples/jsm/effects/AsciiEffect.js +14 -1
- package/examples/jsm/exporters/DRACOExporter.js +27 -6
- package/examples/jsm/exporters/GLTFExporter.js +114 -12
- package/examples/jsm/exporters/PLYExporter.js +286 -73
- package/examples/jsm/exporters/USDZExporter.js +347 -112
- 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/LoftGeometry.js +355 -0
- package/examples/jsm/helpers/LightProbeGridHelper.js +1 -1
- package/examples/jsm/helpers/LightProbeHelper.js +5 -4
- package/examples/jsm/helpers/ViewHelper.js +16 -6
- package/examples/jsm/inspector/Inspector.js +53 -15
- package/examples/jsm/inspector/RendererInspector.js +152 -36
- package/examples/jsm/inspector/extensions/tsl-graph/TSLGraphEditor.js +1 -1
- package/examples/jsm/inspector/extensions/tsl-graph/TSLGraphLoader.js +1 -1
- package/examples/jsm/inspector/tabs/Console.js +200 -18
- package/examples/jsm/inspector/tabs/Memory.js +8 -0
- package/examples/jsm/inspector/tabs/Parameters.js +64 -4
- package/examples/jsm/inspector/tabs/Performance.js +21 -6
- package/examples/jsm/inspector/tabs/Settings.js +51 -9
- package/examples/jsm/inspector/tabs/Timeline.js +178 -93
- package/examples/jsm/inspector/tabs/Viewer.js +628 -16
- 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 +1 -1
- package/examples/jsm/inspector/ui/Profiler.js +90 -45
- package/examples/jsm/inspector/ui/Style.js +1788 -1401
- package/examples/jsm/inspector/ui/Tab.js +5 -3
- package/examples/jsm/inspector/ui/Values.js +71 -6
- package/examples/jsm/inspector/ui/utils.js +130 -10
- 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_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/LightProbeGrid.js +106 -76
- package/examples/jsm/lines/LineMaterial.js +38 -15
- package/examples/jsm/lines/LineSegments2.js +8 -0
- package/examples/jsm/lines/webgpu/LineSegments2.js +8 -0
- package/examples/jsm/loaders/3DMLoader.js +1 -1
- package/examples/jsm/loaders/DRACOLoader.js +46 -13
- package/examples/jsm/loaders/EXRLoader.js +27 -55
- package/examples/jsm/loaders/HDRLoader.js +6 -28
- package/examples/jsm/loaders/KTX2Loader.js +31 -12
- package/examples/jsm/loaders/LDrawLoader.js +8 -8
- package/examples/jsm/loaders/LUT3dlLoader.js +2 -2
- package/examples/jsm/loaders/LUTCubeLoader.js +2 -2
- package/examples/jsm/loaders/LWOLoader.js +4 -0
- package/examples/jsm/loaders/LottieLoader.js +1 -1
- package/examples/jsm/loaders/MaterialXLoader.js +31 -9
- package/examples/jsm/loaders/NRRDLoader.js +3 -3
- package/examples/jsm/loaders/PCDLoader.js +7 -7
- package/examples/jsm/loaders/PLYLoader.js +218 -55
- package/examples/jsm/loaders/SVGLoader.js +547 -495
- package/examples/jsm/loaders/TTFLoader.js +1 -1
- package/examples/jsm/loaders/USDLoader.js +33 -9
- package/examples/jsm/loaders/VRMLLoader.js +1 -1
- package/examples/jsm/loaders/usd/USDAParser.js +93 -20
- package/examples/jsm/loaders/usd/USDCParser.js +1 -1
- package/examples/jsm/loaders/usd/USDComposer.js +52 -19
- package/examples/jsm/misc/TileCreasedNormalsPlugin.js +270 -0
- package/examples/jsm/misc/Volume.js +2 -2
- package/examples/jsm/objects/GroundedSkybox.js +1 -1
- package/examples/jsm/objects/Reflector.js +2 -3
- package/examples/jsm/objects/Water2Mesh.js +1 -1
- package/examples/jsm/physics/AmmoPhysics.js +15 -8
- package/examples/jsm/physics/RapierPhysics.js +27 -2
- package/examples/jsm/shaders/VolumeShader.js +31 -44
- package/examples/jsm/transpiler/GLSLDecoder.js +6 -6
- package/examples/jsm/transpiler/Linker.js +1 -1
- package/examples/jsm/tsl/display/BloomNode.js +59 -19
- package/examples/jsm/tsl/display/DepthOfFieldNode.js +2 -2
- package/examples/jsm/tsl/display/FXAANode.js +11 -12
- package/examples/jsm/tsl/display/GTAONode.js +34 -13
- package/examples/jsm/tsl/display/GodraysNode.js +1 -1
- package/examples/jsm/tsl/display/ImportanceSampledEnvironment.js +560 -0
- package/examples/jsm/tsl/display/PixelationPassNode.js +2 -2
- package/examples/jsm/tsl/display/RecurrentDenoiseNode.js +912 -0
- package/examples/jsm/tsl/display/SSAAPassNode.js +13 -25
- package/examples/jsm/tsl/display/SSGINode.js +89 -39
- package/examples/jsm/tsl/display/SSRNode.js +829 -132
- package/examples/jsm/tsl/display/SSSNode.js +2 -2
- package/examples/jsm/tsl/display/TemporalReprojectNode.js +1023 -0
- package/examples/jsm/tsl/lighting/ClusteredLightsNode.js +622 -0
- package/examples/jsm/tsl/lighting/DynamicLightsNode.js +1 -1
- 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 +126 -59
- package/examples/jsm/utils/GeometryCompressionUtils.js +1 -1
- package/examples/jsm/utils/SceneOptimizer.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/package.json +7 -7
- package/src/Three.TSL.js +10 -3
- package/src/Three.WebGPU.js +4 -0
- package/src/animation/AnimationAction.js +15 -11
- package/src/animation/AnimationClip.js +0 -139
- package/src/animation/KeyframeTrack.js +2 -2
- package/src/animation/PropertyBinding.js +2 -2
- package/src/cameras/Camera.js +2 -2
- package/src/cameras/StereoCamera.js +5 -2
- package/src/constants.js +1 -1
- package/src/core/BufferGeometry.js +29 -7
- package/src/core/Object3D.js +17 -7
- package/src/core/Raycaster.js +1 -1
- package/src/core/RenderTarget.js +15 -2
- package/src/extras/PMREMGenerator.js +6 -4
- package/src/extras/TextureUtils.js +1 -1
- package/src/extras/core/ShapePath.js +149 -160
- package/src/geometries/SphereGeometry.js +8 -3
- package/src/helpers/DirectionalLightHelper.js +2 -0
- package/src/helpers/HemisphereLightHelper.js +2 -0
- package/src/helpers/PointLightHelper.js +2 -0
- package/src/helpers/SpotLightHelper.js +1 -1
- package/src/loaders/DataTextureLoader.js +69 -38
- package/src/loaders/LoadingManager.js +5 -0
- package/src/loaders/MaterialLoader.js +36 -266
- package/src/loaders/ObjectLoader.js +3 -1
- package/src/materials/LineBasicMaterial.js +4 -0
- package/src/materials/Material.js +196 -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 +40 -1
- package/src/materials/MeshMatcapMaterial.js +25 -1
- package/src/materials/MeshNormalMaterial.js +9 -1
- package/src/materials/MeshPhongMaterial.js +40 -1
- package/src/materials/MeshPhysicalMaterial.js +38 -0
- package/src/materials/MeshStandardMaterial.js +42 -1
- package/src/materials/MeshToonMaterial.js +34 -1
- package/src/materials/PointsMaterial.js +7 -0
- package/src/materials/ShaderMaterial.js +86 -0
- package/src/materials/SpriteMaterial.js +7 -0
- package/src/materials/nodes/Line2NodeMaterial.js +378 -322
- 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 +0 -30
- package/src/materials/nodes/MeshSSSNodeMaterial.js +0 -13
- package/src/materials/nodes/MeshStandardNodeMaterial.js +0 -11
- package/src/materials/nodes/NodeMaterial.js +115 -71
- package/src/materials/nodes/SpriteNodeMaterial.js +0 -10
- package/src/materials/nodes/manager/NodeMaterialObserver.js +49 -20
- package/src/math/Box3.js +5 -0
- package/src/math/FrustumArray.js +103 -133
- package/src/math/Interpolant.js +1 -1
- package/src/math/MathUtils.js +2 -2
- package/src/math/Matrix3.js +11 -0
- package/src/math/Matrix4.js +28 -3
- package/src/math/Vector2.js +2 -2
- package/src/math/Vector3.js +2 -2
- package/src/math/Vector4.js +2 -2
- package/src/math/interpolants/BezierInterpolant.js +4 -6
- package/src/nodes/Nodes.js +2 -5
- package/src/nodes/TSL.js +8 -6
- package/src/nodes/accessors/Arrays.js +4 -4
- package/src/nodes/accessors/Batch.js +108 -0
- package/src/nodes/accessors/Bitangent.js +2 -2
- package/src/nodes/accessors/BufferAttributeNode.js +13 -2
- package/src/nodes/accessors/Camera.js +7 -7
- package/src/nodes/accessors/ClippingNode.js +1 -1
- package/src/nodes/accessors/Instance.js +264 -0
- package/src/nodes/accessors/MaterialNode.js +18 -2
- package/src/nodes/accessors/MaterialProperties.js +4 -3
- package/src/nodes/accessors/{MorphNode.js → Morph.js} +99 -112
- package/src/nodes/accessors/Normal.js +13 -13
- package/src/nodes/accessors/Position.js +5 -1
- package/src/nodes/accessors/ReferenceNode.js +1 -0
- package/src/nodes/accessors/ReflectVector.js +3 -3
- package/src/nodes/accessors/SceneProperties.js +1 -1
- package/src/nodes/accessors/Skinning.js +263 -0
- package/src/nodes/accessors/StorageBufferNode.js +2 -2
- package/src/nodes/accessors/StorageTexture3DNode.js +100 -0
- package/src/nodes/accessors/StorageTextureNode.js +39 -7
- package/src/nodes/accessors/Tangent.js +4 -4
- package/src/nodes/accessors/TextureNode.js +60 -5
- package/src/nodes/code/FunctionNode.js +2 -16
- package/src/nodes/core/MRTNode.js +7 -2
- package/src/nodes/core/Node.js +39 -2
- package/src/nodes/core/NodeBuilder.js +201 -41
- package/src/nodes/core/NodeUtils.js +13 -13
- package/src/nodes/core/OutputStructNode.js +1 -1
- package/src/nodes/core/OverrideContextNode.js +153 -0
- package/src/nodes/core/PropertyNode.js +51 -5
- package/src/nodes/core/StackNode.js +56 -34
- package/src/nodes/core/StructNode.js +4 -6
- package/src/nodes/core/StructTypeNode.js +6 -6
- package/src/nodes/core/VarNode.js +8 -0
- package/src/nodes/core/VaryingNode.js +12 -2
- package/src/nodes/display/BlendModes.js +1 -41
- package/src/nodes/display/BumpMapNode.js +6 -1
- package/src/nodes/display/ColorAdjustment.js +10 -9
- package/src/nodes/display/FrontFacingNode.js +38 -9
- package/src/nodes/display/NormalMapNode.js +2 -2
- package/src/nodes/display/PassNode.js +35 -43
- package/src/nodes/display/PremultiplyAlphaFunctions.js +39 -0
- package/src/nodes/display/RenderOutputNode.js +12 -3
- package/src/nodes/functions/VolumetricLightingModel.js +40 -7
- package/src/nodes/gpgpu/WorkgroupInfoNode.js +1 -1
- package/src/nodes/lighting/EnvironmentNode.js +2 -2
- package/src/nodes/lighting/IESSpotLightNode.js +40 -2
- package/src/nodes/lighting/LightingContextNode.js +10 -2
- package/src/nodes/lighting/LightsNode.js +90 -37
- package/src/nodes/lighting/PointShadowNode.js +6 -1
- package/src/nodes/lighting/ShadowFilterNode.js +21 -52
- package/src/nodes/lighting/ShadowNode.js +34 -14
- package/src/nodes/materialx/lib/mx_noise.js +2 -2
- package/src/nodes/math/ConditionalNode.js +3 -3
- package/src/nodes/math/MathNode.js +39 -11
- package/src/nodes/math/OperatorNode.js +23 -23
- package/src/nodes/parsers/GLSLNodeFunction.js +1 -1
- package/src/nodes/pmrem/PMREMNode.js +33 -2
- package/src/nodes/tsl/TSLCore.js +63 -18
- package/src/nodes/utils/EquirectUV.js +30 -5
- package/src/nodes/utils/FunctionOverloadingNode.js +1 -1
- package/src/nodes/utils/Packing.js +35 -4
- package/src/nodes/utils/RTTNode.js +40 -24
- package/src/nodes/utils/ReflectorNode.js +1 -0
- package/src/nodes/utils/StorageArrayElementNode.js +1 -1
- package/src/objects/BatchedMesh.js +22 -14
- package/src/objects/InstancedMesh.js +0 -11
- package/src/objects/Skeleton.js +0 -9
- package/src/renderers/WebGLRenderer.js +19 -15
- package/src/renderers/common/Backend.js +49 -5
- package/src/renderers/common/Bindings.js +114 -45
- package/src/renderers/common/Buffer.js +9 -0
- package/src/renderers/common/ClippingContext.js +10 -2
- package/src/renderers/common/Info.js +63 -22
- package/src/renderers/common/Lighting.js +53 -5
- package/src/renderers/common/RenderList.js +41 -4
- package/src/renderers/common/RenderObject.js +73 -13
- package/src/renderers/common/Renderer.js +281 -108
- package/src/renderers/common/Sampler.js +16 -48
- package/src/renderers/common/Textures.js +32 -5
- package/src/renderers/common/TimestampQueryPool.js +1 -1
- package/src/renderers/common/UniformsGroup.js +31 -9
- package/src/renderers/common/XRManager.js +340 -22
- package/src/renderers/common/extras/PMREMGenerator.js +15 -38
- package/src/renderers/common/nodes/NodeBuilderState.js +9 -1
- package/src/renderers/common/nodes/NodeLibrary.js +4 -4
- package/src/renderers/common/nodes/NodeManager.js +63 -14
- package/src/renderers/common/nodes/NodeUniformBuffer.js +13 -0
- 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_fragment.glsl.js +1 -1
- 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/lights_fragment_begin.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/lights_pars_begin.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/normal_fragment_begin.glsl.js +2 -2
- package/src/renderers/shaders/ShaderChunk/normal_vertex.glsl.js +6 -0
- package/src/renderers/shaders/ShaderChunk/shadowmap_vertex.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/transmission_fragment.glsl.js +1 -1
- package/src/renderers/shaders/ShaderLib/distance.glsl.js +1 -1
- package/src/renderers/webgl/WebGLOutput.js +2 -1
- package/src/renderers/webgl/WebGLProgram.js +5 -4
- package/src/renderers/webgl/WebGLPrograms.js +12 -5
- package/src/renderers/webgl/WebGLRenderLists.js +9 -1
- package/src/renderers/webgl/WebGLShaderCache.js +5 -11
- package/src/renderers/webgl/WebGLTextures.js +20 -7
- package/src/renderers/webgl/WebGLUniformsGroups.js +66 -38
- package/src/renderers/webgl-fallback/WebGLBackend.js +84 -25
- package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +138 -8
- package/src/renderers/webgl-fallback/utils/WebGLAttributeUtils.js +1 -1
- package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +52 -22
- package/src/renderers/webgl-fallback/utils/WebGLUtils.js +4 -2
- package/src/renderers/webgpu/WebGPUBackend.js +480 -169
- 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 +164 -7
- package/src/renderers/webgpu/nodes/WGSLNodeFunction.js +1 -1
- package/src/renderers/webgpu/utils/WebGPUAttributeUtils.js +98 -38
- package/src/renderers/webgpu/utils/WebGPUBindingUtils.js +72 -68
- package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +164 -69
- package/src/renderers/webgpu/utils/WebGPUTexturePassUtils.js +158 -95
- package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +297 -141
- package/src/renderers/webgpu/utils/WebGPUTimestampQueryPool.js +33 -18
- package/src/renderers/webgpu/utils/WebGPUUtils.js +38 -3
- package/src/textures/DepthTexture.js +1 -1
- package/src/textures/ExternalTexture.js +0 -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/inspector/extensions/extensions.json +0 -6
- 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/tsl/display/AnamorphicNode.js +0 -293
- package/examples/jsm/tsl/lighting/TiledLightsNode.js +0 -442
- package/src/nodes/accessors/BatchNode.js +0 -163
- package/src/nodes/accessors/InstanceNode.js +0 -349
- package/src/nodes/accessors/InstancedMeshNode.js +0 -50
- package/src/nodes/accessors/SkinningNode.js +0 -328
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
import { BufferAttribute } from 'three';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A plugin for `3d-tiles-renderer` that computes creased vertex normals for the
|
|
5
|
+
* geometry of each loaded tile: smooth normals everywhere except where faces meet
|
|
6
|
+
* at an angle greater than the crease angle. Useful for photogrammetry tile sets
|
|
7
|
+
* like Google Photorealistic 3D Tiles which come without vertex normals.
|
|
8
|
+
*
|
|
9
|
+
* The normals are computed in a Web Worker so tile processing doesn't block the
|
|
10
|
+
* main thread. Tiles are displayed once their normals are ready.
|
|
11
|
+
*
|
|
12
|
+
* ```js
|
|
13
|
+
* tiles.registerPlugin( new TileCreasedNormalsPlugin( { creaseAngle: Math.PI / 6 } ) );
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* @three_import import { TileCreasedNormalsPlugin } from 'three/addons/misc/TileCreasedNormalsPlugin.js';
|
|
17
|
+
*/
|
|
18
|
+
class TileCreasedNormalsPlugin {
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Constructs a new plugin.
|
|
22
|
+
*
|
|
23
|
+
* @param {Object} [options] - The configuration options.
|
|
24
|
+
* @param {number} [options.creaseAngle=Math.PI/3] - The crease angle in radians.
|
|
25
|
+
*/
|
|
26
|
+
constructor( { creaseAngle = Math.PI / 3 } = {} ) {
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The crease angle in radians.
|
|
30
|
+
*
|
|
31
|
+
* @type {number}
|
|
32
|
+
*/
|
|
33
|
+
this.creaseAngle = creaseAngle;
|
|
34
|
+
|
|
35
|
+
this._requestId = 0;
|
|
36
|
+
this._pending = new Map();
|
|
37
|
+
|
|
38
|
+
const workerCode = `
|
|
39
|
+
|
|
40
|
+
${ computeCreasedNormals.toString() }
|
|
41
|
+
|
|
42
|
+
onmessage = ( { data } ) => {
|
|
43
|
+
|
|
44
|
+
const { id, positions, creaseAngle } = data;
|
|
45
|
+
const normals = computeCreasedNormals( positions, creaseAngle );
|
|
46
|
+
postMessage( { id, positions, normals }, [ positions.buffer, normals.buffer ] );
|
|
47
|
+
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
`;
|
|
51
|
+
|
|
52
|
+
this._worker = new Worker( URL.createObjectURL( new Blob( [ workerCode ] ) ) );
|
|
53
|
+
this._worker.onmessage = ( { data } ) => {
|
|
54
|
+
|
|
55
|
+
this._pending.get( data.id )( data );
|
|
56
|
+
this._pending.delete( data.id );
|
|
57
|
+
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Called by the tiles renderer for each loaded tile model. The tile is
|
|
64
|
+
* displayed once the returned promise resolves.
|
|
65
|
+
*
|
|
66
|
+
* @param {Object3D} scene - The tile model.
|
|
67
|
+
* @return {Promise} A promise that resolves when all geometries have creased normals.
|
|
68
|
+
*/
|
|
69
|
+
processTileModel( scene ) {
|
|
70
|
+
|
|
71
|
+
const promises = [];
|
|
72
|
+
|
|
73
|
+
scene.traverse( ( mesh ) => {
|
|
74
|
+
|
|
75
|
+
if ( mesh.geometry ) {
|
|
76
|
+
|
|
77
|
+
promises.push( this._processMesh( mesh ) );
|
|
78
|
+
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
} );
|
|
82
|
+
|
|
83
|
+
return Promise.all( promises );
|
|
84
|
+
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
_processMesh( mesh ) {
|
|
88
|
+
|
|
89
|
+
const geometry = mesh.geometry.index ? mesh.geometry.toNonIndexed() : mesh.geometry;
|
|
90
|
+
const positions = geometry.attributes.position.array;
|
|
91
|
+
|
|
92
|
+
const id = this._requestId ++;
|
|
93
|
+
this._worker.postMessage( { id, positions, creaseAngle: this.creaseAngle }, [ positions.buffer ] );
|
|
94
|
+
|
|
95
|
+
return new Promise( ( resolve ) => {
|
|
96
|
+
|
|
97
|
+
this._pending.set( id, ( { positions, normals } ) => {
|
|
98
|
+
|
|
99
|
+
geometry.setAttribute( 'position', new BufferAttribute( positions, 3 ) );
|
|
100
|
+
geometry.setAttribute( 'normal', new BufferAttribute( normals, 3 ) );
|
|
101
|
+
mesh.geometry = geometry;
|
|
102
|
+
resolve();
|
|
103
|
+
|
|
104
|
+
} );
|
|
105
|
+
|
|
106
|
+
} );
|
|
107
|
+
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Called by the tiles renderer when the plugin is unregistered or the
|
|
112
|
+
* tiles renderer is disposed.
|
|
113
|
+
*/
|
|
114
|
+
dispose() {
|
|
115
|
+
|
|
116
|
+
this._worker.terminate();
|
|
117
|
+
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// Computes creased normals for non-indexed triangle positions. The function is
|
|
123
|
+
// self-contained so it can be serialized into the worker.
|
|
124
|
+
function computeCreasedNormals( positions, creaseAngle ) {
|
|
125
|
+
|
|
126
|
+
const creaseDot = Math.cos( creaseAngle );
|
|
127
|
+
const hashMultiplier = ( 1 + 1e-10 ) * 1e2;
|
|
128
|
+
|
|
129
|
+
const vertexCount = positions.length / 3;
|
|
130
|
+
const faceCount = vertexCount / 3;
|
|
131
|
+
|
|
132
|
+
// compute the normal of each face
|
|
133
|
+
const faceNormals = new Float64Array( faceCount * 3 );
|
|
134
|
+
for ( let f = 0; f < faceCount; f ++ ) {
|
|
135
|
+
|
|
136
|
+
const f9 = 9 * f;
|
|
137
|
+
const ax = positions[ f9 + 0 ], ay = positions[ f9 + 1 ], az = positions[ f9 + 2 ];
|
|
138
|
+
const bx = positions[ f9 + 3 ], by = positions[ f9 + 4 ], bz = positions[ f9 + 5 ];
|
|
139
|
+
const cx = positions[ f9 + 6 ], cy = positions[ f9 + 7 ], cz = positions[ f9 + 8 ];
|
|
140
|
+
|
|
141
|
+
const v1x = cx - bx, v1y = cy - by, v1z = cz - bz;
|
|
142
|
+
const v2x = ax - bx, v2y = ay - by, v2z = az - bz;
|
|
143
|
+
|
|
144
|
+
const nx = v1y * v2z - v1z * v2y;
|
|
145
|
+
const ny = v1z * v2x - v1x * v2z;
|
|
146
|
+
const nz = v1x * v2y - v1y * v2x;
|
|
147
|
+
|
|
148
|
+
const invLength = 1 / ( Math.sqrt( nx * nx + ny * ny + nz * nz ) || 1 );
|
|
149
|
+
faceNormals[ 3 * f + 0 ] = nx * invLength;
|
|
150
|
+
faceNormals[ 3 * f + 1 ] = ny * invLength;
|
|
151
|
+
faceNormals[ 3 * f + 2 ] = nz * invLength;
|
|
152
|
+
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// assign an id to each vertex, sharing the id between vertices with the same
|
|
156
|
+
// quantized position via an open-addressed hash table (slots hold id + 1, 0 means empty)
|
|
157
|
+
const vertexIds = new Int32Array( vertexCount );
|
|
158
|
+
const quantized = new Int32Array( vertexCount * 3 );
|
|
159
|
+
|
|
160
|
+
let tableSize = 1;
|
|
161
|
+
while ( tableSize < vertexCount * 2 ) tableSize <<= 1;
|
|
162
|
+
const tableMask = tableSize - 1;
|
|
163
|
+
const table = new Int32Array( tableSize );
|
|
164
|
+
|
|
165
|
+
let uniqueCount = 0;
|
|
166
|
+
for ( let i = 0; i < vertexCount; i ++ ) {
|
|
167
|
+
|
|
168
|
+
const i3 = 3 * i;
|
|
169
|
+
const qx = ~ ~ ( positions[ i3 + 0 ] * hashMultiplier );
|
|
170
|
+
const qy = ~ ~ ( positions[ i3 + 1 ] * hashMultiplier );
|
|
171
|
+
const qz = ~ ~ ( positions[ i3 + 2 ] * hashMultiplier );
|
|
172
|
+
|
|
173
|
+
let slot = ( Math.imul( qx, 73856093 ) ^ Math.imul( qy, 19349663 ) ^ Math.imul( qz, 83492791 ) ) & tableMask;
|
|
174
|
+
|
|
175
|
+
while ( true ) {
|
|
176
|
+
|
|
177
|
+
const id = table[ slot ];
|
|
178
|
+
|
|
179
|
+
if ( id === 0 ) {
|
|
180
|
+
|
|
181
|
+
const q3 = 3 * uniqueCount;
|
|
182
|
+
quantized[ q3 + 0 ] = qx;
|
|
183
|
+
quantized[ q3 + 1 ] = qy;
|
|
184
|
+
quantized[ q3 + 2 ] = qz;
|
|
185
|
+
|
|
186
|
+
table[ slot ] = uniqueCount + 1;
|
|
187
|
+
vertexIds[ i ] = uniqueCount ++;
|
|
188
|
+
break;
|
|
189
|
+
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
const q3 = 3 * ( id - 1 );
|
|
193
|
+
|
|
194
|
+
if ( quantized[ q3 + 0 ] === qx && quantized[ q3 + 1 ] === qy && quantized[ q3 + 2 ] === qz ) {
|
|
195
|
+
|
|
196
|
+
vertexIds[ i ] = id - 1;
|
|
197
|
+
break;
|
|
198
|
+
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
slot = ( slot + 1 ) & tableMask;
|
|
202
|
+
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// bucket the faces surrounding each unique vertex position
|
|
208
|
+
const bucketOffsets = new Int32Array( uniqueCount + 1 );
|
|
209
|
+
for ( let i = 0; i < vertexCount; i ++ ) bucketOffsets[ vertexIds[ i ] + 1 ] ++;
|
|
210
|
+
for ( let i = 0; i < uniqueCount; i ++ ) bucketOffsets[ i + 1 ] += bucketOffsets[ i ];
|
|
211
|
+
|
|
212
|
+
const bucketFaces = new Int32Array( vertexCount );
|
|
213
|
+
const bucketCursors = bucketOffsets.slice( 0, uniqueCount );
|
|
214
|
+
for ( let f = 0; f < faceCount; f ++ ) {
|
|
215
|
+
|
|
216
|
+
const f3 = 3 * f;
|
|
217
|
+
bucketFaces[ bucketCursors[ vertexIds[ f3 + 0 ] ] ++ ] = f;
|
|
218
|
+
bucketFaces[ bucketCursors[ vertexIds[ f3 + 1 ] ] ++ ] = f;
|
|
219
|
+
bucketFaces[ bucketCursors[ vertexIds[ f3 + 2 ] ] ++ ] = f;
|
|
220
|
+
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// average the normals of the faces surrounding each vertex if they are within the
|
|
224
|
+
// provided crease threshold
|
|
225
|
+
const normalArray = new Float32Array( vertexCount * 3 );
|
|
226
|
+
for ( let f = 0; f < faceCount; f ++ ) {
|
|
227
|
+
|
|
228
|
+
const f3 = 3 * f;
|
|
229
|
+
const nx = faceNormals[ f3 + 0 ];
|
|
230
|
+
const ny = faceNormals[ f3 + 1 ];
|
|
231
|
+
const nz = faceNormals[ f3 + 2 ];
|
|
232
|
+
|
|
233
|
+
for ( let n = 0; n < 3; n ++ ) {
|
|
234
|
+
|
|
235
|
+
const i = f3 + n;
|
|
236
|
+
const id = vertexIds[ i ];
|
|
237
|
+
|
|
238
|
+
let sumX = 0, sumY = 0, sumZ = 0;
|
|
239
|
+
|
|
240
|
+
for ( let k = bucketOffsets[ id ], end = bucketOffsets[ id + 1 ]; k < end; k ++ ) {
|
|
241
|
+
|
|
242
|
+
const o3 = 3 * bucketFaces[ k ];
|
|
243
|
+
const ox = faceNormals[ o3 + 0 ];
|
|
244
|
+
const oy = faceNormals[ o3 + 1 ];
|
|
245
|
+
const oz = faceNormals[ o3 + 2 ];
|
|
246
|
+
|
|
247
|
+
if ( nx * ox + ny * oy + nz * oz > creaseDot ) {
|
|
248
|
+
|
|
249
|
+
sumX += ox;
|
|
250
|
+
sumY += oy;
|
|
251
|
+
sumZ += oz;
|
|
252
|
+
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
const invLength = 1 / ( Math.sqrt( sumX * sumX + sumY * sumY + sumZ * sumZ ) || 1 );
|
|
258
|
+
normalArray[ 3 * i + 0 ] = sumX * invLength;
|
|
259
|
+
normalArray[ 3 * i + 1 ] = sumY * invLength;
|
|
260
|
+
normalArray[ 3 * i + 2 ] = sumZ * invLength;
|
|
261
|
+
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
return normalArray;
|
|
267
|
+
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
export { TileCreasedNormalsPlugin };
|
|
@@ -122,7 +122,7 @@ class Volume {
|
|
|
122
122
|
case 'unsigned long long int' :
|
|
123
123
|
case 'uint64' :
|
|
124
124
|
case 'uint64_t' :
|
|
125
|
-
throw new Error( '
|
|
125
|
+
throw new Error( 'THREE.Volume: type is not supported in JavaScript.' );
|
|
126
126
|
case 'Float32' :
|
|
127
127
|
case 'float32' :
|
|
128
128
|
case 'float' :
|
|
@@ -140,7 +140,7 @@ class Volume {
|
|
|
140
140
|
|
|
141
141
|
if ( this.data.length !== this.xLength * this.yLength * this.zLength ) {
|
|
142
142
|
|
|
143
|
-
throw new Error( '
|
|
143
|
+
throw new Error( 'THREE.Volume: lengths are not matching arrayBuffer size.' );
|
|
144
144
|
|
|
145
145
|
}
|
|
146
146
|
|
|
@@ -32,7 +32,7 @@ class GroundedSkybox extends Mesh {
|
|
|
32
32
|
|
|
33
33
|
if ( height <= 0 || radius <= 0 || resolution <= 0 ) {
|
|
34
34
|
|
|
35
|
-
throw new Error( 'GroundedSkybox height, radius, and resolution must be positive.' );
|
|
35
|
+
throw new Error( 'THREE.GroundedSkybox: height, radius, and resolution must be positive.' );
|
|
36
36
|
|
|
37
37
|
}
|
|
38
38
|
|
|
@@ -115,7 +115,7 @@ class Reflector extends Mesh {
|
|
|
115
115
|
|
|
116
116
|
this.onBeforeRender = function ( renderer, scene, camera ) {
|
|
117
117
|
|
|
118
|
-
const reflectionCamera = this.
|
|
118
|
+
const reflectionCamera = this.getReflectionCamera( camera );
|
|
119
119
|
|
|
120
120
|
reflectorWorldPosition.setFromMatrixPosition( scope.matrixWorld );
|
|
121
121
|
cameraWorldPosition.setFromMatrixPosition( camera.matrixWorld );
|
|
@@ -278,11 +278,10 @@ class Reflector extends Mesh {
|
|
|
278
278
|
* Returns a reflection camera for the given camera. The reflection camera is used to
|
|
279
279
|
* render the scene from the reflector's view so correct reflections can be produced.
|
|
280
280
|
*
|
|
281
|
-
* @private
|
|
282
281
|
* @param {Camera} camera - The scene's camera.
|
|
283
282
|
* @return {Camera} The corresponding reflection camera.
|
|
284
283
|
*/
|
|
285
|
-
this.
|
|
284
|
+
this.getReflectionCamera = function ( camera ) {
|
|
286
285
|
|
|
287
286
|
let reflectionCamera = this._reflectionCameras.get( camera );
|
|
288
287
|
|
|
@@ -66,7 +66,7 @@ class WaterNode extends TempNode {
|
|
|
66
66
|
|
|
67
67
|
this.normalMap0 = texture( options.normalMap0 );
|
|
68
68
|
this.normalMap1 = texture( options.normalMap1 );
|
|
69
|
-
this.flowMap = texture( options.flowMap
|
|
69
|
+
this.flowMap = texture( options.flowMap );
|
|
70
70
|
|
|
71
71
|
this.color = uniform( options.color !== undefined ? new Color( options.color ) : new Color( 0xffffff ) );
|
|
72
72
|
this.flowDirection = uniform( options.flowDirection !== undefined ? options.flowDirection : new Vector2( 1, 0 ) );
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
+
const AMMO_PATH = 'https://cdn.jsdelivr.net/gh/kripken/ammo.js@79190a1f03845794b1bba1777f30037349967658/builds/ammo.wasm.js';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* @classdesc Can be used to include Ammo.js as a Physics engine into
|
|
3
|
-
* `three.js` apps.
|
|
4
|
-
* ```
|
|
5
|
-
* <script src="jsm/libs/ammo.wasm.js"></script>
|
|
6
|
-
* ```
|
|
7
|
-
* It is then possible to initialize the API via:
|
|
5
|
+
* `three.js` apps. The API can be initialized via:
|
|
8
6
|
* ```js
|
|
9
7
|
* const physics = await AmmoPhysics();
|
|
10
8
|
* ```
|
|
9
|
+
* The component automatically imports Ammo.js from a CDN so make sure
|
|
10
|
+
* to use the component with an active Internet connection.
|
|
11
11
|
*
|
|
12
12
|
* @name AmmoPhysics
|
|
13
13
|
* @class
|
|
@@ -16,10 +16,17 @@
|
|
|
16
16
|
*/
|
|
17
17
|
async function AmmoPhysics() {
|
|
18
18
|
|
|
19
|
-
if (
|
|
19
|
+
if ( typeof Ammo === 'undefined' ) {
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
await new Promise( ( resolve, reject ) => {
|
|
22
|
+
|
|
23
|
+
const script = document.createElement( 'script' );
|
|
24
|
+
script.src = AMMO_PATH;
|
|
25
|
+
script.onload = resolve;
|
|
26
|
+
script.onerror = reject;
|
|
27
|
+
document.head.appendChild( script );
|
|
28
|
+
|
|
29
|
+
} );
|
|
23
30
|
|
|
24
31
|
}
|
|
25
32
|
|
|
@@ -281,6 +281,20 @@ async function RapierPhysics() {
|
|
|
281
281
|
|
|
282
282
|
}
|
|
283
283
|
|
|
284
|
+
function applyImpulse( mesh, impulse, index = 0 ) {
|
|
285
|
+
|
|
286
|
+
let { body } = meshMap.get( mesh );
|
|
287
|
+
|
|
288
|
+
if ( mesh.isInstancedMesh ) {
|
|
289
|
+
|
|
290
|
+
body = body[ index ];
|
|
291
|
+
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
body.applyImpulse( impulse, true );
|
|
295
|
+
|
|
296
|
+
}
|
|
297
|
+
|
|
284
298
|
function addHeightfield( mesh, width, depth, heights, scale ) {
|
|
285
299
|
|
|
286
300
|
const shape = RAPIER.ColliderDesc.heightfield( width, depth, heights, scale );
|
|
@@ -414,7 +428,7 @@ async function RapierPhysics() {
|
|
|
414
428
|
|
|
415
429
|
/**
|
|
416
430
|
* Adds a heightfield terrain to the physics simulation.
|
|
417
|
-
*
|
|
431
|
+
*
|
|
418
432
|
* @method
|
|
419
433
|
* @name RapierPhysics#addHeightfield
|
|
420
434
|
* @param {Mesh} mesh - The Three.js mesh representing the terrain.
|
|
@@ -427,7 +441,18 @@ async function RapierPhysics() {
|
|
|
427
441
|
* @param {number} scale.z - Scale factor for depth.
|
|
428
442
|
* @returns {RigidBody} The created Rapier rigid body for the heightfield.
|
|
429
443
|
*/
|
|
430
|
-
addHeightfield: addHeightfield
|
|
444
|
+
addHeightfield: addHeightfield,
|
|
445
|
+
|
|
446
|
+
/**
|
|
447
|
+
* Applies an impulse to the given mesh which is part of the physics simulation.
|
|
448
|
+
*
|
|
449
|
+
* @method
|
|
450
|
+
* @name RapierPhysics#applyImpulse
|
|
451
|
+
* @param {Mesh} mesh - The mesh to apply the impulse to.
|
|
452
|
+
* @param {Vector3} impulse - The impulse to apply.
|
|
453
|
+
* @param {number} [index=0] - If the mesh is instanced, the index represents the instanced ID.
|
|
454
|
+
*/
|
|
455
|
+
applyImpulse: applyImpulse
|
|
431
456
|
|
|
432
457
|
};
|
|
433
458
|
|
|
@@ -31,34 +31,23 @@ const VolumeRenderShader1 = {
|
|
|
31
31
|
|
|
32
32
|
vertexShader: /* glsl */`
|
|
33
33
|
|
|
34
|
-
varying vec4 v_nearpos;
|
|
35
|
-
varying vec4 v_farpos;
|
|
36
34
|
varying vec3 v_position;
|
|
35
|
+
varying vec3 v_cameraInObj;
|
|
36
|
+
varying vec3 v_viewDirInObj;
|
|
37
37
|
|
|
38
38
|
void main() {
|
|
39
|
-
// Prepare transforms to map to "camera view". See also:
|
|
40
|
-
// https://threejs.org/docs/#api/renderers/webgl/WebGLProgram
|
|
41
|
-
mat4 viewtransformf = modelViewMatrix;
|
|
42
|
-
mat4 viewtransformi = inverse(modelViewMatrix);
|
|
43
|
-
|
|
44
|
-
// Project local vertex coordinate to camera position. Then do a step
|
|
45
|
-
// backward (in cam coords) to the near clipping plane, and project back. Do
|
|
46
|
-
// the same for the far clipping plane. This gives us all the information we
|
|
47
|
-
// need to calculate the ray and truncate it to the viewing cone.
|
|
48
39
|
vec4 position4 = vec4(position, 1.0);
|
|
49
|
-
vec4 pos_in_cam = viewtransformf * position4;
|
|
50
40
|
|
|
51
|
-
|
|
52
|
-
pos_in_cam.z = -pos_in_cam.w;
|
|
53
|
-
v_nearpos = viewtransformi * pos_in_cam;
|
|
41
|
+
v_position = position;
|
|
54
42
|
|
|
55
|
-
//
|
|
56
|
-
|
|
57
|
-
|
|
43
|
+
// Express the camera position and view direction in the object's local
|
|
44
|
+
// space so the fragment shader can build the per-fragment view ray.
|
|
45
|
+
// For perspective cameras, rays converge at v_cameraInObj.
|
|
46
|
+
// For orthographic cameras, rays travel along v_viewDirInObj.
|
|
47
|
+
v_cameraInObj = (inverse(modelMatrix) * vec4(cameraPosition, 1.0)).xyz;
|
|
48
|
+
v_viewDirInObj = (inverse(modelViewMatrix) * vec4(0.0, 0.0, -1.0, 0.0)).xyz;
|
|
58
49
|
|
|
59
|
-
|
|
60
|
-
v_position = position;
|
|
61
|
-
gl_Position = projectionMatrix * viewMatrix * modelMatrix * position4;
|
|
50
|
+
gl_Position = projectionMatrix * modelViewMatrix * position4;
|
|
62
51
|
}`,
|
|
63
52
|
|
|
64
53
|
fragmentShader: /* glsl */`
|
|
@@ -75,8 +64,8 @@ const VolumeRenderShader1 = {
|
|
|
75
64
|
uniform sampler2D u_cmdata;
|
|
76
65
|
|
|
77
66
|
varying vec3 v_position;
|
|
78
|
-
varying
|
|
79
|
-
varying
|
|
67
|
+
varying vec3 v_cameraInObj;
|
|
68
|
+
varying vec3 v_viewDirInObj;
|
|
80
69
|
|
|
81
70
|
// The maximum distance through our rendering volume is sqrt(3).
|
|
82
71
|
const int MAX_STEPS = 887; // 887 for 512^3, 1774 for 1024^3
|
|
@@ -96,33 +85,29 @@ const VolumeRenderShader1 = {
|
|
|
96
85
|
|
|
97
86
|
|
|
98
87
|
void main() {
|
|
99
|
-
//
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
//
|
|
108
|
-
//
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
distance = max(distance, min((-0.5 - v_position.z) / view_ray.z,
|
|
115
|
-
(u_size.z - 0.5 - v_position.z) / view_ray.z));
|
|
116
|
-
|
|
117
|
-
// Now we have the starting position on the front surface
|
|
118
|
-
vec3 front = v_position + view_ray * distance;
|
|
88
|
+
// Per-fragment ray direction in object space, pointing from the back
|
|
89
|
+
// face toward the camera. For perspective cameras the rays converge
|
|
90
|
+
// at the camera position; for orthographic cameras they are parallel
|
|
91
|
+
// to the view direction.
|
|
92
|
+
vec3 view_ray = isOrthographic
|
|
93
|
+
? normalize(-v_viewDirInObj)
|
|
94
|
+
: normalize(v_cameraInObj - v_position);
|
|
95
|
+
|
|
96
|
+
// Slab-based ray/AABB intersection: v_position lies on the back face
|
|
97
|
+
// of the cuboid, so stepping along view_ray traverses the volume and
|
|
98
|
+
// exits through the front face at t = distance.
|
|
99
|
+
vec3 t1 = (vec3(-0.5) - v_position) / view_ray;
|
|
100
|
+
vec3 t2 = (u_size - vec3(0.5) - v_position) / view_ray;
|
|
101
|
+
vec3 tmax = max(t1, t2);
|
|
102
|
+
float distance = min(min(tmax.x, tmax.y), tmax.z);
|
|
119
103
|
|
|
120
104
|
// Decide how many steps to take
|
|
121
|
-
int nsteps = int(
|
|
105
|
+
int nsteps = int(distance / relative_step_size + 0.5);
|
|
122
106
|
if ( nsteps < 1 )
|
|
123
107
|
discard;
|
|
124
108
|
|
|
125
109
|
// Get starting location and step vector in texture coordinates
|
|
110
|
+
vec3 front = v_position + view_ray * distance;
|
|
126
111
|
vec3 step = ((v_position - front) / u_size) / float(nsteps);
|
|
127
112
|
vec3 start_loc = front / u_size;
|
|
128
113
|
|
|
@@ -149,6 +134,8 @@ const VolumeRenderShader1 = {
|
|
|
149
134
|
|
|
150
135
|
vec4 apply_colormap(float val) {
|
|
151
136
|
val = (val - u_clim[0]) / (u_clim[1] - u_clim[0]);
|
|
137
|
+
float n = float(textureSize(u_cmdata, 0).x); // see #33842
|
|
138
|
+
val = (val * (n - 1.0) + 0.5) / n;
|
|
152
139
|
return texture2D(u_cmdata, vec2(val, 0.5));
|
|
153
140
|
}
|
|
154
141
|
|
|
@@ -677,7 +677,7 @@ class GLSLDecoder {
|
|
|
677
677
|
|
|
678
678
|
params.push( new FunctionParameter( type, name, qualifier, immutable ) );
|
|
679
679
|
|
|
680
|
-
if ( tokens[ i ] && tokens[ i ].str !== ',' ) throw new Error( 'Expected ","' );
|
|
680
|
+
if ( tokens[ i ] && tokens[ i ].str !== ',' ) throw new Error( 'THREE.GLSLDecoder: Expected ","' );
|
|
681
681
|
|
|
682
682
|
}
|
|
683
683
|
|
|
@@ -789,7 +789,7 @@ class GLSLDecoder {
|
|
|
789
789
|
|
|
790
790
|
if ( tokens[ 2 ].str !== '{' ) {
|
|
791
791
|
|
|
792
|
-
throw new Error( 'Expected \'{\' after struct name ' );
|
|
792
|
+
throw new Error( 'THREE.GLSLDecoder: Expected \'{\' after struct name ' );
|
|
793
793
|
|
|
794
794
|
}
|
|
795
795
|
|
|
@@ -801,13 +801,13 @@ class GLSLDecoder {
|
|
|
801
801
|
|
|
802
802
|
if ( typeToken.type != 'literal' || nameToken.type != 'literal' ) {
|
|
803
803
|
|
|
804
|
-
throw new Error( 'Invalid struct declaration' );
|
|
804
|
+
throw new Error( 'THREE.GLSLDecoder: Invalid struct declaration' );
|
|
805
805
|
|
|
806
806
|
}
|
|
807
807
|
|
|
808
808
|
if ( tokens[ i + 2 ].str !== ';' ) {
|
|
809
809
|
|
|
810
|
-
throw new Error( 'Missing \';\' after struct member name' );
|
|
810
|
+
throw new Error( 'THREE.GLSLDecoder: Missing \';\' after struct member name' );
|
|
811
811
|
|
|
812
812
|
}
|
|
813
813
|
|
|
@@ -818,7 +818,7 @@ class GLSLDecoder {
|
|
|
818
818
|
|
|
819
819
|
if ( tokens[ tokens.length - 2 ].str !== '}' ) {
|
|
820
820
|
|
|
821
|
-
throw new Error( 'Missing closing \'}\' for struct ' + structName );
|
|
821
|
+
throw new Error( 'THREE.GLSLDecoder: Missing closing \'}\' for struct ' + structName );
|
|
822
822
|
|
|
823
823
|
}
|
|
824
824
|
|
|
@@ -921,7 +921,7 @@ class GLSLDecoder {
|
|
|
921
921
|
// Validate curly braces
|
|
922
922
|
if ( this.getToken().str !== '{' ) {
|
|
923
923
|
|
|
924
|
-
throw new Error( 'Expected \'{\' after switch(...) ' );
|
|
924
|
+
throw new Error( 'THREE.GLSLDecoder: Expected \'{\' after switch(...) ' );
|
|
925
925
|
|
|
926
926
|
}
|
|
927
927
|
|