super-three 0.168.0 → 0.169.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/build/three.cjs +384 -700
- package/build/three.module.js +384 -700
- package/build/three.module.min.js +1 -1
- package/build/three.webgpu.js +24644 -22406
- package/build/three.webgpu.min.js +1 -1
- package/build/three.webgpu.nodes.js +79941 -0
- package/build/three.webgpu.nodes.min.js +6 -0
- package/examples/jsm/Addons.js +0 -6
- package/examples/jsm/controls/TrackballControls.js +32 -12
- package/examples/jsm/controls/TransformControls.js +97 -62
- package/examples/jsm/exporters/DRACOExporter.js +4 -2
- package/examples/jsm/exporters/EXRExporter.js +19 -11
- package/examples/jsm/exporters/KTX2Exporter.js +21 -13
- package/examples/jsm/exporters/OBJExporter.js +5 -1
- package/examples/jsm/exporters/PLYExporter.js +9 -7
- package/examples/jsm/geometries/DecalGeometry.js +4 -1
- package/examples/jsm/geometries/InstancedPointsGeometry.js +1 -1
- package/examples/jsm/helpers/LightProbeHelper.js +1 -1
- package/examples/jsm/helpers/LightProbeHelperGPU.js +65 -0
- package/examples/jsm/libs/basis/basis_transcoder.js +8 -10
- package/examples/jsm/libs/basis/basis_transcoder.wasm +0 -0
- package/examples/jsm/libs/ktx-parse.module.js +1 -1
- package/examples/jsm/lights/LightProbeGenerator.js +24 -10
- package/examples/jsm/loaders/ColladaLoader.js +9 -6
- package/examples/jsm/loaders/DRACOLoader.js +3 -1
- package/examples/jsm/loaders/FBXLoader.js +30 -20
- package/examples/jsm/loaders/GLTFLoader.js +5 -10
- package/examples/jsm/loaders/KTX2Loader.js +10 -7
- package/examples/jsm/loaders/MTLLoader.js +4 -3
- package/examples/jsm/loaders/MaterialXLoader.js +29 -10
- package/examples/jsm/loaders/OBJLoader.js +5 -3
- package/examples/jsm/loaders/PCDLoader.js +5 -4
- package/examples/jsm/loaders/PDBLoader.js +3 -2
- package/examples/jsm/loaders/PLYLoader.js +8 -5
- package/examples/jsm/loaders/STLLoader.js +3 -2
- package/examples/jsm/loaders/VRMLLoader.js +10 -10
- package/examples/jsm/loaders/VTKLoader.js +4 -3
- package/examples/jsm/loaders/XYZLoader.js +3 -2
- package/examples/jsm/misc/Timer.js +1 -1
- package/examples/jsm/modifiers/CurveModifierGPU.js +233 -0
- package/examples/jsm/objects/LensflareMesh.js +322 -0
- package/examples/jsm/objects/SkyMesh.js +1 -2
- package/examples/jsm/objects/Water2Mesh.js +2 -3
- package/examples/jsm/objects/WaterMesh.js +1 -2
- package/examples/jsm/physics/JoltPhysics.js +1 -1
- package/examples/jsm/physics/RapierPhysics.js +1 -1
- package/examples/jsm/transpiler/GLSLDecoder.js +1 -1
- package/examples/jsm/transpiler/ShaderToyDecoder.js +2 -2
- package/examples/jsm/utils/GeometryCompressionUtils.js +37 -122
- package/examples/jsm/utils/ShadowMapViewer.js +3 -8
- package/examples/jsm/utils/ShadowMapViewerGPU.js +201 -0
- package/examples/jsm/utils/SkeletonUtils.js +84 -66
- package/examples/jsm/utils/TextureUtils.js +1 -0
- package/examples/jsm/utils/TextureUtilsGPU.js +63 -0
- package/examples/jsm/webxr/XRControllerModelFactory.js +1 -1
- package/package.json +2 -2
- package/src/Three.WebGPU.Nodes.js +200 -0
- package/src/Three.WebGPU.js +2 -1
- package/src/audio/Audio.js +2 -2
- package/src/constants.js +1 -1
- package/src/core/BufferAttribute.js +0 -9
- package/src/core/Clock.js +1 -1
- package/src/core/InterleavedBuffer.js +0 -9
- package/src/extras/Controls.js +1 -1
- package/src/geometries/CylinderGeometry.js +11 -4
- package/src/loaders/MaterialLoader.js +7 -1
- package/src/loaders/nodes/NodeLoader.js +24 -4
- package/src/loaders/nodes/NodeMaterialLoader.js +21 -17
- package/src/loaders/nodes/NodeObjectLoader.js +19 -0
- package/src/materials/nodes/InstancedPointsNodeMaterial.js +19 -34
- package/src/materials/nodes/Line2NodeMaterial.js +26 -26
- package/src/materials/nodes/LineBasicNodeMaterial.js +7 -3
- package/src/materials/nodes/LineDashedNodeMaterial.js +7 -3
- package/src/materials/nodes/MeshBasicNodeMaterial.js +7 -3
- package/src/materials/nodes/MeshLambertNodeMaterial.js +7 -3
- package/src/materials/nodes/MeshMatcapNodeMaterial.js +7 -3
- package/src/materials/nodes/MeshNormalNodeMaterial.js +7 -3
- package/src/materials/nodes/MeshPhongNodeMaterial.js +7 -3
- package/src/materials/nodes/MeshPhysicalNodeMaterial.js +6 -3
- package/src/materials/nodes/MeshSSSNodeMaterial.js +6 -3
- package/src/materials/nodes/MeshStandardNodeMaterial.js +7 -3
- package/src/materials/nodes/MeshToonNodeMaterial.js +7 -3
- package/src/materials/nodes/NodeMaterial.js +20 -45
- package/src/materials/nodes/NodeMaterials.js +2 -0
- package/src/materials/nodes/PointsNodeMaterial.js +7 -3
- package/src/materials/nodes/ShadowNodeMaterial.js +7 -3
- package/src/materials/nodes/SpriteNodeMaterial.js +39 -6
- package/src/materials/nodes/VolumeNodeMaterial.js +13 -9
- package/src/materials/nodes/manager/NodeMaterialObserver.js +302 -0
- package/src/math/Triangle.js +24 -0
- package/src/nodes/Nodes.js +3 -3
- package/src/nodes/TSL.js +96 -93
- package/src/nodes/accessors/BatchNode.js +7 -3
- package/src/nodes/accessors/BufferAttributeNode.js +6 -3
- package/src/nodes/accessors/BufferNode.js +6 -3
- package/src/nodes/accessors/Camera.js +10 -16
- package/src/nodes/accessors/ClippingNode.js +7 -3
- package/src/nodes/accessors/CubeTextureNode.js +6 -3
- package/src/nodes/accessors/InstanceNode.js +11 -11
- package/src/nodes/accessors/InstancedPointsMaterialNode.js +6 -3
- package/src/nodes/accessors/Lights.js +51 -0
- package/src/nodes/accessors/MaterialNode.js +8 -4
- package/src/nodes/accessors/MaterialReferenceNode.js +6 -3
- package/src/nodes/accessors/ModelNode.js +42 -7
- package/src/nodes/accessors/ModelViewProjectionNode.js +9 -5
- package/src/nodes/accessors/MorphNode.js +7 -3
- package/src/nodes/accessors/Normal.js +32 -6
- package/src/nodes/accessors/Object3DNode.js +11 -27
- package/src/nodes/accessors/PointUVNode.js +7 -3
- package/src/nodes/accessors/ReferenceBaseNode.js +32 -4
- package/src/nodes/accessors/ReferenceNode.js +40 -3
- package/src/nodes/accessors/RendererReferenceNode.js +9 -3
- package/src/nodes/accessors/SceneNode.js +7 -3
- package/src/nodes/accessors/SkinningNode.js +7 -3
- package/src/nodes/accessors/StorageBufferNode.js +21 -3
- package/src/nodes/accessors/StorageTextureNode.js +7 -4
- package/src/nodes/accessors/Texture3DNode.js +7 -4
- package/src/nodes/accessors/TextureNode.js +19 -8
- package/src/nodes/accessors/TextureSizeNode.js +8 -5
- package/src/nodes/accessors/UniformArrayNode.js +12 -9
- package/src/nodes/accessors/UserDataNode.js +9 -6
- package/src/nodes/accessors/VelocityNode.js +74 -23
- package/src/nodes/accessors/VertexColorNode.js +6 -3
- package/src/nodes/code/CodeNode.js +7 -3
- package/src/nodes/code/ExpressionNode.js +8 -4
- package/src/nodes/code/FunctionCallNode.js +6 -3
- package/src/nodes/code/FunctionNode.js +6 -3
- package/src/nodes/code/ScriptableNode.js +11 -6
- package/src/nodes/code/ScriptableValueNode.js +7 -3
- package/src/nodes/core/AssignNode.js +9 -6
- package/src/nodes/core/AttributeNode.js +7 -3
- package/src/nodes/core/BypassNode.js +8 -4
- package/src/nodes/core/CacheNode.js +8 -4
- package/src/nodes/core/ConstNode.js +6 -3
- package/src/nodes/core/ContextNode.js +7 -3
- package/src/nodes/core/IndexNode.js +25 -3
- package/src/nodes/core/InputNode.js +7 -3
- package/src/nodes/core/MRTNode.js +6 -3
- package/src/nodes/core/Node.js +10 -51
- package/src/nodes/core/NodeBuilder.js +71 -5
- package/src/nodes/core/NodeUtils.js +48 -6
- package/src/nodes/core/OutputStructNode.js +8 -4
- package/src/nodes/core/ParameterNode.js +6 -3
- package/src/nodes/core/PropertyNode.js +7 -3
- package/src/nodes/core/StackNode.js +7 -3
- package/src/nodes/core/StructTypeNode.js +7 -3
- package/src/nodes/core/TempNode.js +8 -4
- package/src/nodes/core/UniformGroupNode.js +10 -6
- package/src/nodes/core/UniformNode.js +6 -3
- package/src/nodes/core/VarNode.js +8 -4
- package/src/nodes/core/VaryingNode.js +7 -3
- package/src/nodes/display/AfterImageNode.js +6 -0
- package/src/nodes/display/AnaglyphPassNode.js +6 -0
- package/src/nodes/display/AnamorphicNode.js +6 -0
- package/src/nodes/display/BloomNode.js +6 -0
- package/src/nodes/display/BumpMapNode.js +6 -0
- package/src/nodes/display/ColorSpaceFunctions.js +4 -4
- package/src/nodes/display/ColorSpaceNode.js +43 -14
- package/src/nodes/display/DenoiseNode.js +6 -3
- package/src/nodes/display/DepthOfFieldNode.js +6 -3
- package/src/nodes/display/DotScreenNode.js +8 -5
- package/src/nodes/display/FXAANode.js +6 -3
- package/src/nodes/display/FilmNode.js +6 -3
- package/src/nodes/display/FrontFacingNode.js +7 -3
- package/src/nodes/display/GTAONode.js +6 -3
- package/src/nodes/display/GaussianBlurNode.js +6 -3
- package/src/nodes/display/Lut3DNode.js +6 -3
- package/src/nodes/display/NormalMapNode.js +8 -6
- package/src/nodes/display/ParallaxBarrierPassNode.js +8 -5
- package/src/nodes/display/PassNode.js +18 -7
- package/src/nodes/display/PixelationPassNode.js +12 -5
- package/src/nodes/display/PosterizeNode.js +6 -3
- package/src/nodes/display/RGBShiftNode.js +6 -3
- package/src/nodes/display/RenderOutputNode.js +12 -8
- package/src/nodes/display/SSAAPassNode.js +6 -3
- package/src/nodes/display/ScreenNode.js +181 -0
- package/src/nodes/display/SobelOperatorNode.js +6 -3
- package/src/nodes/display/StereoCompositePassNode.js +6 -3
- package/src/nodes/display/StereoPassNode.js +6 -3
- package/src/nodes/display/ToneMappingFunctions.js +12 -12
- package/src/nodes/display/ToneMappingNode.js +8 -7
- package/src/nodes/display/ToonOutlinePassNode.js +111 -0
- package/src/nodes/display/TransitionNode.js +6 -3
- package/src/nodes/display/ViewportDepthNode.js +7 -3
- package/src/nodes/display/ViewportDepthTextureNode.js +8 -5
- package/src/nodes/display/ViewportSharedTextureNode.js +8 -5
- package/src/nodes/display/ViewportTextureNode.js +8 -5
- package/src/nodes/fog/FogExp2Node.js +6 -3
- package/src/nodes/fog/FogNode.js +7 -3
- package/src/nodes/fog/FogRangeNode.js +6 -3
- package/src/nodes/functions/PhysicalLightingModel.js +2 -2
- package/src/nodes/functions/material/getShIrradianceAt.js +28 -0
- package/src/nodes/geometry/RangeNode.js +7 -3
- package/src/nodes/gpgpu/AtomicFunctionNode.js +99 -0
- package/src/nodes/gpgpu/BarrierNode.js +40 -0
- package/src/nodes/gpgpu/ComputeBuiltinNode.js +98 -0
- package/src/nodes/gpgpu/ComputeNode.js +8 -4
- package/src/nodes/gpgpu/WorkgroupInfoNode.js +100 -0
- package/src/nodes/lighting/AONode.js +6 -3
- package/src/nodes/lighting/AmbientLightNode.js +6 -3
- package/src/nodes/lighting/AnalyticLightNode.js +198 -30
- package/src/nodes/lighting/BasicEnvironmentNode.js +6 -3
- package/src/nodes/lighting/BasicLightMapNode.js +6 -3
- package/src/nodes/lighting/DirectionalLightNode.js +7 -4
- package/src/nodes/lighting/EnvironmentNode.js +6 -3
- package/src/nodes/lighting/HemisphereLightNode.js +10 -6
- package/src/nodes/lighting/IESSpotLightNode.js +6 -3
- package/src/nodes/lighting/IrradianceNode.js +6 -3
- package/src/nodes/lighting/LightProbeNode.js +8 -31
- package/src/nodes/lighting/LightingContextNode.js +6 -3
- package/src/nodes/lighting/LightingNode.js +7 -3
- package/src/nodes/lighting/LightsNode.js +24 -5
- package/src/nodes/lighting/PointLightNode.js +11 -7
- package/src/nodes/lighting/RectAreaLightNode.js +11 -7
- package/src/nodes/lighting/SpotLightNode.js +13 -10
- package/src/nodes/math/ConditionalNode.js +23 -6
- package/src/nodes/math/MathNode.js +6 -3
- package/src/nodes/math/OperatorNode.js +6 -3
- package/src/nodes/pmrem/PMREMNode.js +6 -3
- package/src/nodes/utils/ArrayElementNode.js +8 -4
- package/src/nodes/utils/ConvertNode.js +7 -3
- package/src/nodes/utils/CubeMapNode.js +6 -3
- package/src/nodes/utils/EquirectUVNode.js +6 -3
- package/src/nodes/utils/FlipNode.js +7 -4
- package/src/nodes/utils/FunctionOverloadingNode.js +7 -3
- package/src/nodes/utils/JoinNode.js +6 -3
- package/src/nodes/utils/LoopNode.js +7 -3
- package/src/nodes/utils/MatcapUVNode.js +6 -3
- package/src/nodes/utils/MaxMipLevelNode.js +6 -3
- package/src/nodes/utils/OscNode.js +7 -3
- package/src/nodes/utils/RTTNode.js +6 -3
- package/src/nodes/utils/ReflectorNode.js +8 -5
- package/src/nodes/utils/RemapNode.js +7 -3
- package/src/nodes/utils/RotateNode.js +6 -3
- package/src/nodes/utils/SetNode.js +7 -4
- package/src/nodes/utils/SplitNode.js +7 -3
- package/src/nodes/utils/SpriteSheetUVNode.js +7 -3
- package/src/nodes/utils/StorageArrayElementNode.js +9 -8
- package/src/nodes/utils/TimerNode.js +6 -3
- package/src/nodes/utils/TriplanarTexturesNode.js +7 -3
- package/src/nodes/utils/ViewportUtils.js +2 -2
- package/src/objects/BatchedMesh.js +76 -10
- package/src/objects/LOD.js +21 -0
- package/src/objects/Line.js +1 -0
- package/src/objects/Mesh.js +7 -23
- package/src/objects/Points.js +2 -0
- package/src/renderers/WebGLRenderer.js +65 -50
- package/src/renderers/common/BundleGroup.js +26 -0
- package/src/renderers/common/ClippingContext.js +4 -3
- package/src/renderers/common/RenderContext.js +4 -5
- package/src/renderers/common/RenderObject.js +116 -5
- package/src/renderers/common/RenderObjects.js +8 -1
- package/src/renderers/common/Renderer.js +57 -49
- package/src/renderers/common/extras/PMREMGenerator.js +7 -9
- package/src/renderers/common/nodes/NodeBuilderState.js +3 -3
- package/src/renderers/common/nodes/Nodes.js +33 -14
- package/src/renderers/shaders/ShaderLib/sprite.glsl.js +2 -4
- package/src/renderers/webgl/WebGLAttributes.js +45 -14
- package/src/renderers/webgl/WebGLCapabilities.js +9 -0
- package/src/renderers/webgl/WebGLProgram.js +2 -0
- package/src/renderers/webgl/WebGLPrograms.js +21 -17
- package/src/renderers/webgl/WebGLState.js +21 -0
- package/src/renderers/webgl/WebGLTextures.js +22 -0
- package/src/renderers/webgl-fallback/WebGLBackend.js +50 -45
- package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +4 -4
- package/src/renderers/webgl-fallback/utils/WebGLAttributeUtils.js +6 -0
- package/src/renderers/webgl-fallback/utils/WebGLState.js +1 -4
- package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +61 -16
- package/src/renderers/webgpu/WebGPUBackend.js +33 -25
- package/src/renderers/webgpu/WebGPURenderer.Nodes.js +42 -0
- package/src/renderers/webgpu/WebGPURenderer.js +5 -2
- package/src/renderers/webgpu/nodes/BasicNodeLibrary.js +59 -0
- package/src/renderers/{common → webgpu}/nodes/StandardNodeLibrary.js +11 -11
- package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +91 -11
- package/src/renderers/webgpu/utils/WebGPUAttributeUtils.js +6 -16
- package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +1 -1
- package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +7 -5
- package/src/renderers/webgpu/utils/WebGPUUtils.js +1 -1
- package/src/utils.js +33 -1
- package/examples/jsm/geometries/SDFGeometryGenerator.js +0 -144
- package/examples/jsm/loaders/TiltLoader.js +0 -520
- package/examples/jsm/utils/GPUStatsPanel.js +0 -95
- package/examples/jsm/utils/PackedPhongMaterial.js +0 -178
- package/src/nodes/display/ViewportNode.js +0 -138
- package/src/nodes/lighting/LightNode.js +0 -57
- package/src/renderers/common/StandardRenderer.js +0 -18
- package/src/renderers/webvr/WebVRManager.js +0 -495
- package/src/renderers/webvr/WebVRUtils.js +0 -66
|
@@ -11,27 +11,19 @@ import {
|
|
|
11
11
|
Matrix4,
|
|
12
12
|
Vector3
|
|
13
13
|
} from 'three';
|
|
14
|
-
import { PackedPhongMaterial } from './PackedPhongMaterial.js';
|
|
15
14
|
|
|
16
15
|
|
|
17
16
|
|
|
18
17
|
/**
|
|
19
|
-
* Make the input
|
|
20
|
-
* Also will change the mesh.material to `PackedPhongMaterial` which let the vertex shader program decode the normal data.
|
|
18
|
+
* Make the input geometry's normal attribute encoded and compressed by 3 different methods.
|
|
21
19
|
*
|
|
22
|
-
* @param {THREE.
|
|
20
|
+
* @param {THREE.BufferGeometry} geometry
|
|
23
21
|
* @param {String} encodeMethod "DEFAULT" || "OCT1Byte" || "OCT2Byte" || "ANGLES"
|
|
24
22
|
*
|
|
25
23
|
*/
|
|
26
|
-
function compressNormals(
|
|
24
|
+
function compressNormals( geometry, encodeMethod ) {
|
|
27
25
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
console.error( 'Mesh must contain geometry. ' );
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const normal = mesh.geometry.attributes.normal;
|
|
26
|
+
const normal = geometry.attributes.normal;
|
|
35
27
|
|
|
36
28
|
if ( ! normal ) {
|
|
37
29
|
|
|
@@ -66,8 +58,8 @@ function compressNormals( mesh, encodeMethod ) {
|
|
|
66
58
|
|
|
67
59
|
}
|
|
68
60
|
|
|
69
|
-
|
|
70
|
-
|
|
61
|
+
geometry.setAttribute( 'normal', new BufferAttribute( result, 3, true ) );
|
|
62
|
+
geometry.attributes.normal.bytes = result.length * 1;
|
|
71
63
|
|
|
72
64
|
} else if ( encodeMethod == 'OCT1Byte' ) {
|
|
73
65
|
|
|
@@ -88,8 +80,8 @@ function compressNormals( mesh, encodeMethod ) {
|
|
|
88
80
|
|
|
89
81
|
}
|
|
90
82
|
|
|
91
|
-
|
|
92
|
-
|
|
83
|
+
geometry.setAttribute( 'normal', new BufferAttribute( result, 2, true ) );
|
|
84
|
+
geometry.attributes.normal.bytes = result.length * 1;
|
|
93
85
|
|
|
94
86
|
} else if ( encodeMethod == 'OCT2Byte' ) {
|
|
95
87
|
|
|
@@ -104,8 +96,8 @@ function compressNormals( mesh, encodeMethod ) {
|
|
|
104
96
|
|
|
105
97
|
}
|
|
106
98
|
|
|
107
|
-
|
|
108
|
-
|
|
99
|
+
geometry.setAttribute( 'normal', new BufferAttribute( result, 2, true ) );
|
|
100
|
+
geometry.attributes.normal.bytes = result.length * 2;
|
|
109
101
|
|
|
110
102
|
} else if ( encodeMethod == 'ANGLES' ) {
|
|
111
103
|
|
|
@@ -120,8 +112,8 @@ function compressNormals( mesh, encodeMethod ) {
|
|
|
120
112
|
|
|
121
113
|
}
|
|
122
114
|
|
|
123
|
-
|
|
124
|
-
|
|
115
|
+
geometry.setAttribute( 'normal', new BufferAttribute( result, 2, true ) );
|
|
116
|
+
geometry.attributes.normal.bytes = result.length * 2;
|
|
125
117
|
|
|
126
118
|
} else {
|
|
127
119
|
|
|
@@ -129,60 +121,22 @@ function compressNormals( mesh, encodeMethod ) {
|
|
|
129
121
|
|
|
130
122
|
}
|
|
131
123
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
// modify material
|
|
137
|
-
if ( ! ( mesh.material instanceof PackedPhongMaterial ) ) {
|
|
138
|
-
|
|
139
|
-
mesh.material = new PackedPhongMaterial().copy( mesh.material );
|
|
140
|
-
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
if ( encodeMethod == 'ANGLES' ) {
|
|
144
|
-
|
|
145
|
-
mesh.material.defines.USE_PACKED_NORMAL = 0;
|
|
146
|
-
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
if ( encodeMethod == 'OCT1Byte' ) {
|
|
150
|
-
|
|
151
|
-
mesh.material.defines.USE_PACKED_NORMAL = 1;
|
|
152
|
-
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
if ( encodeMethod == 'OCT2Byte' ) {
|
|
156
|
-
|
|
157
|
-
mesh.material.defines.USE_PACKED_NORMAL = 1;
|
|
158
|
-
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
if ( encodeMethod == 'DEFAULT' ) {
|
|
162
|
-
|
|
163
|
-
mesh.material.defines.USE_PACKED_NORMAL = 2;
|
|
164
|
-
|
|
165
|
-
}
|
|
124
|
+
geometry.attributes.normal.needsUpdate = true;
|
|
125
|
+
geometry.attributes.normal.isPacked = true;
|
|
126
|
+
geometry.attributes.normal.packingMethod = encodeMethod;
|
|
166
127
|
|
|
167
128
|
}
|
|
168
129
|
|
|
169
130
|
|
|
170
131
|
/**
|
|
171
|
-
* Make the input
|
|
172
|
-
* Also will change the mesh.material to `PackedPhongMaterial` which let the vertex shader program decode the position data.
|
|
132
|
+
* Make the input geometry's position attribute encoded and compressed.
|
|
173
133
|
*
|
|
174
|
-
* @param {THREE.
|
|
134
|
+
* @param {THREE.BufferGeometry} geometry
|
|
175
135
|
*
|
|
176
136
|
*/
|
|
177
|
-
function compressPositions(
|
|
137
|
+
function compressPositions( geometry ) {
|
|
178
138
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
console.error( 'Mesh must contain geometry. ' );
|
|
182
|
-
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
const position = mesh.geometry.attributes.position;
|
|
139
|
+
const position = geometry.attributes.position;
|
|
186
140
|
|
|
187
141
|
if ( ! position ) {
|
|
188
142
|
|
|
@@ -204,47 +158,27 @@ function compressPositions( mesh ) {
|
|
|
204
158
|
const result = quantizedEncode( array, encodingBytes );
|
|
205
159
|
|
|
206
160
|
const quantized = result.quantized;
|
|
207
|
-
const decodeMat = result.decodeMat;
|
|
208
161
|
|
|
209
162
|
// IMPORTANT: calculate original geometry bounding info first, before updating packed positions
|
|
210
|
-
if (
|
|
211
|
-
if (
|
|
163
|
+
if ( geometry.boundingBox == null ) geometry.computeBoundingBox();
|
|
164
|
+
if ( geometry.boundingSphere == null ) geometry.computeBoundingSphere();
|
|
212
165
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
// modify material
|
|
219
|
-
if ( ! ( mesh.material instanceof PackedPhongMaterial ) ) {
|
|
220
|
-
|
|
221
|
-
mesh.material = new PackedPhongMaterial().copy( mesh.material );
|
|
222
|
-
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
mesh.material.defines.USE_PACKED_POSITION = 0;
|
|
226
|
-
|
|
227
|
-
mesh.material.uniforms.quantizeMatPos.value = decodeMat;
|
|
228
|
-
mesh.material.uniforms.quantizeMatPos.needsUpdate = true;
|
|
166
|
+
geometry.setAttribute( 'position', new BufferAttribute( quantized, 3 ) );
|
|
167
|
+
geometry.attributes.position.isPacked = true;
|
|
168
|
+
geometry.attributes.position.needsUpdate = true;
|
|
169
|
+
geometry.attributes.position.bytes = quantized.length * encodingBytes;
|
|
229
170
|
|
|
230
171
|
}
|
|
231
172
|
|
|
232
173
|
/**
|
|
233
|
-
* Make the input
|
|
234
|
-
* Also will change the mesh.material to `PackedPhongMaterial` which let the vertex shader program decode the uv data.
|
|
174
|
+
* Make the input geometry's uv attribute encoded and compressed.
|
|
235
175
|
*
|
|
236
|
-
* @param {THREE.
|
|
176
|
+
* @param {THREE.BufferGeometry} geometry
|
|
237
177
|
*
|
|
238
178
|
*/
|
|
239
|
-
function compressUvs(
|
|
179
|
+
function compressUvs( geometry ) {
|
|
240
180
|
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
console.error( 'Mesh must contain geometry property. ' );
|
|
244
|
-
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
const uvs = mesh.geometry.attributes.uv;
|
|
181
|
+
const uvs = geometry.attributes.uv;
|
|
248
182
|
|
|
249
183
|
if ( ! uvs ) {
|
|
250
184
|
|
|
@@ -281,39 +215,20 @@ function compressUvs( mesh ) {
|
|
|
281
215
|
|
|
282
216
|
}
|
|
283
217
|
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
if ( ! ( mesh.material instanceof PackedPhongMaterial ) ) {
|
|
290
|
-
|
|
291
|
-
mesh.material = new PackedPhongMaterial().copy( mesh.material );
|
|
292
|
-
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
mesh.material.defines.USE_PACKED_UV = 0;
|
|
218
|
+
geometry.setAttribute( 'uv', new BufferAttribute( result, 2, true ) );
|
|
219
|
+
geometry.attributes.uv.isPacked = true;
|
|
220
|
+
geometry.attributes.uv.needsUpdate = true;
|
|
221
|
+
geometry.attributes.uv.bytes = result.length * 2;
|
|
296
222
|
|
|
297
223
|
} else {
|
|
298
224
|
|
|
299
225
|
// use quantized encoding method
|
|
300
226
|
result = quantizedEncodeUV( array, 2 );
|
|
301
227
|
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
if ( ! ( mesh.material instanceof PackedPhongMaterial ) ) {
|
|
308
|
-
|
|
309
|
-
mesh.material = new PackedPhongMaterial().copy( mesh.material );
|
|
310
|
-
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
mesh.material.defines.USE_PACKED_UV = 1;
|
|
314
|
-
|
|
315
|
-
mesh.material.uniforms.quantizeMatUV.value = result.decodeMat;
|
|
316
|
-
mesh.material.uniforms.quantizeMatUV.needsUpdate = true;
|
|
228
|
+
geometry.setAttribute( 'uv', new BufferAttribute( result.quantized, 2 ) );
|
|
229
|
+
geometry.attributes.uv.isPacked = true;
|
|
230
|
+
geometry.attributes.uv.needsUpdate = true;
|
|
231
|
+
geometry.attributes.uv.bytes = result.quantized.length * 2;
|
|
317
232
|
|
|
318
233
|
}
|
|
319
234
|
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
DoubleSide,
|
|
3
|
-
|
|
3
|
+
CanvasTexture,
|
|
4
4
|
Mesh,
|
|
5
5
|
MeshBasicMaterial,
|
|
6
6
|
OrthographicCamera,
|
|
7
7
|
PlaneGeometry,
|
|
8
8
|
Scene,
|
|
9
9
|
ShaderMaterial,
|
|
10
|
-
Texture,
|
|
11
10
|
UniformsUtils
|
|
12
11
|
} from 'three';
|
|
13
12
|
import { UnpackDepthRGBAShader } from '../shaders/UnpackDepthRGBAShader.js';
|
|
@@ -93,13 +92,9 @@ class ShadowMapViewer {
|
|
|
93
92
|
context.fillStyle = 'rgba( 255, 0, 0, 1 )';
|
|
94
93
|
context.fillText( light.name, 0, 20 );
|
|
95
94
|
|
|
96
|
-
const labelTexture = new
|
|
97
|
-
labelTexture.magFilter = LinearFilter;
|
|
98
|
-
labelTexture.minFilter = LinearFilter;
|
|
99
|
-
labelTexture.needsUpdate = true;
|
|
95
|
+
const labelTexture = new CanvasTexture( labelCanvas );
|
|
100
96
|
|
|
101
|
-
const labelMaterial = new MeshBasicMaterial( { map: labelTexture, side: DoubleSide } );
|
|
102
|
-
labelMaterial.transparent = true;
|
|
97
|
+
const labelMaterial = new MeshBasicMaterial( { map: labelTexture, side: DoubleSide, transparent: true } );
|
|
103
98
|
|
|
104
99
|
const labelPlane = new PlaneGeometry( labelCanvas.width, labelCanvas.height );
|
|
105
100
|
labelMesh = new Mesh( labelPlane, labelMaterial );
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DoubleSide,
|
|
3
|
+
CanvasTexture,
|
|
4
|
+
Mesh,
|
|
5
|
+
MeshBasicMaterial,
|
|
6
|
+
NodeMaterial,
|
|
7
|
+
OrthographicCamera,
|
|
8
|
+
PlaneGeometry,
|
|
9
|
+
Scene,
|
|
10
|
+
Texture
|
|
11
|
+
} from 'three';
|
|
12
|
+
import { texture } from 'three/tsl';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* This is a helper for visualising a given light's shadow map.
|
|
16
|
+
* It works for shadow casting lights: DirectionalLight and SpotLight.
|
|
17
|
+
* It renders out the shadow map and displays it on a HUD.
|
|
18
|
+
*
|
|
19
|
+
* Example usage:
|
|
20
|
+
* 1) Import ShadowMapViewer into your app.
|
|
21
|
+
*
|
|
22
|
+
* 2) Create a shadow casting light and name it optionally:
|
|
23
|
+
* let light = new DirectionalLight( 0xffffff, 1 );
|
|
24
|
+
* light.castShadow = true;
|
|
25
|
+
* light.name = 'Sun';
|
|
26
|
+
*
|
|
27
|
+
* 3) Create a shadow map viewer for that light and set its size and position optionally:
|
|
28
|
+
* let shadowMapViewer = new ShadowMapViewer( light );
|
|
29
|
+
* shadowMapViewer.size.set( 128, 128 ); //width, height default: 256, 256
|
|
30
|
+
* shadowMapViewer.position.set( 10, 10 ); //x, y in pixel default: 0, 0 (top left corner)
|
|
31
|
+
*
|
|
32
|
+
* 4) Render the shadow map viewer in your render loop:
|
|
33
|
+
* shadowMapViewer.render( renderer );
|
|
34
|
+
*
|
|
35
|
+
* 5) Optionally: Update the shadow map viewer on window resize:
|
|
36
|
+
* shadowMapViewer.updateForWindowResize();
|
|
37
|
+
*
|
|
38
|
+
* 6) If you set the position or size members directly, you need to call shadowMapViewer.update();
|
|
39
|
+
*/
|
|
40
|
+
|
|
41
|
+
class ShadowMapViewer {
|
|
42
|
+
|
|
43
|
+
constructor( light ) {
|
|
44
|
+
|
|
45
|
+
//- Internals
|
|
46
|
+
const scope = this;
|
|
47
|
+
const doRenderLabel = ( light.name !== undefined && light.name !== '' );
|
|
48
|
+
let currentAutoClear;
|
|
49
|
+
|
|
50
|
+
//Holds the initial position and dimension of the HUD
|
|
51
|
+
const frame = {
|
|
52
|
+
x: 10,
|
|
53
|
+
y: 10,
|
|
54
|
+
width: 256,
|
|
55
|
+
height: 256
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const camera = new OrthographicCamera( window.innerWidth / - 2, window.innerWidth / 2, window.innerHeight / 2, window.innerHeight / - 2, 1, 10 );
|
|
59
|
+
camera.position.set( 0, 0, 2 );
|
|
60
|
+
const scene = new Scene();
|
|
61
|
+
|
|
62
|
+
//HUD for shadow map
|
|
63
|
+
|
|
64
|
+
const material = new NodeMaterial();
|
|
65
|
+
|
|
66
|
+
const shadowMapUniform = texture( new Texture() );
|
|
67
|
+
material.fragmentNode = shadowMapUniform;
|
|
68
|
+
|
|
69
|
+
const plane = new PlaneGeometry( frame.width, frame.height );
|
|
70
|
+
const mesh = new Mesh( plane, material );
|
|
71
|
+
|
|
72
|
+
scene.add( mesh );
|
|
73
|
+
|
|
74
|
+
//Label for light's name
|
|
75
|
+
let labelCanvas, labelMesh;
|
|
76
|
+
|
|
77
|
+
if ( doRenderLabel ) {
|
|
78
|
+
|
|
79
|
+
labelCanvas = document.createElement( 'canvas' );
|
|
80
|
+
|
|
81
|
+
const context = labelCanvas.getContext( '2d' );
|
|
82
|
+
context.font = 'Bold 20px Arial';
|
|
83
|
+
|
|
84
|
+
const labelWidth = context.measureText( light.name ).width;
|
|
85
|
+
labelCanvas.width = labelWidth;
|
|
86
|
+
labelCanvas.height = 25; //25 to account for g, p, etc.
|
|
87
|
+
|
|
88
|
+
context.font = 'Bold 20px Arial';
|
|
89
|
+
context.fillStyle = 'rgba( 255, 0, 0, 1 )';
|
|
90
|
+
context.fillText( light.name, 0, 20 );
|
|
91
|
+
|
|
92
|
+
const labelTexture = new CanvasTexture( labelCanvas );
|
|
93
|
+
|
|
94
|
+
const labelMaterial = new MeshBasicMaterial( { map: labelTexture, side: DoubleSide, transparent: true } );
|
|
95
|
+
|
|
96
|
+
const labelPlane = new PlaneGeometry( labelCanvas.width, labelCanvas.height );
|
|
97
|
+
labelMesh = new Mesh( labelPlane, labelMaterial );
|
|
98
|
+
|
|
99
|
+
scene.add( labelMesh );
|
|
100
|
+
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function resetPosition() {
|
|
104
|
+
|
|
105
|
+
scope.position.set( scope.position.x, scope.position.y );
|
|
106
|
+
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
//- API
|
|
110
|
+
// Set to false to disable displaying this shadow map
|
|
111
|
+
this.enabled = true;
|
|
112
|
+
|
|
113
|
+
// Set the size of the displayed shadow map on the HUD
|
|
114
|
+
this.size = {
|
|
115
|
+
width: frame.width,
|
|
116
|
+
height: frame.height,
|
|
117
|
+
set: function ( width, height ) {
|
|
118
|
+
|
|
119
|
+
this.width = width;
|
|
120
|
+
this.height = height;
|
|
121
|
+
|
|
122
|
+
mesh.scale.set( this.width / frame.width, this.height / frame.height, 1 );
|
|
123
|
+
|
|
124
|
+
//Reset the position as it is off when we scale stuff
|
|
125
|
+
resetPosition();
|
|
126
|
+
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
// Set the position of the displayed shadow map on the HUD
|
|
131
|
+
this.position = {
|
|
132
|
+
x: frame.x,
|
|
133
|
+
y: frame.y,
|
|
134
|
+
set: function ( x, y ) {
|
|
135
|
+
|
|
136
|
+
this.x = x;
|
|
137
|
+
this.y = y;
|
|
138
|
+
|
|
139
|
+
const width = scope.size.width;
|
|
140
|
+
const height = scope.size.height;
|
|
141
|
+
|
|
142
|
+
mesh.position.set( - window.innerWidth / 2 + width / 2 + this.x, window.innerHeight / 2 - height / 2 - this.y, 0 );
|
|
143
|
+
|
|
144
|
+
if ( doRenderLabel ) labelMesh.position.set( mesh.position.x, mesh.position.y - scope.size.height / 2 + labelCanvas.height / 2, 0 );
|
|
145
|
+
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
this.render = function ( renderer ) {
|
|
150
|
+
|
|
151
|
+
if ( this.enabled ) {
|
|
152
|
+
|
|
153
|
+
//Because a light's .shadowMap is only initialised after the first render pass
|
|
154
|
+
//we have to make sure the correct map is sent into the shader, otherwise we
|
|
155
|
+
//always end up with the scene's first added shadow casting light's shadowMap
|
|
156
|
+
//in the shader
|
|
157
|
+
//See: https://github.com/mrdoob/three.js/issues/5932
|
|
158
|
+
shadowMapUniform.value = light.shadow.map.texture;
|
|
159
|
+
|
|
160
|
+
currentAutoClear = renderer.autoClear;
|
|
161
|
+
renderer.autoClear = false; // To allow render overlay
|
|
162
|
+
renderer.clearDepth();
|
|
163
|
+
renderer.render( scene, camera );
|
|
164
|
+
renderer.autoClear = currentAutoClear;
|
|
165
|
+
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
this.updateForWindowResize = function () {
|
|
171
|
+
|
|
172
|
+
if ( this.enabled ) {
|
|
173
|
+
|
|
174
|
+
camera.left = window.innerWidth / - 2;
|
|
175
|
+
camera.right = window.innerWidth / 2;
|
|
176
|
+
camera.top = window.innerHeight / 2;
|
|
177
|
+
camera.bottom = window.innerHeight / - 2;
|
|
178
|
+
camera.updateProjectionMatrix();
|
|
179
|
+
|
|
180
|
+
this.update();
|
|
181
|
+
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
this.update = function () {
|
|
187
|
+
|
|
188
|
+
this.position.set( this.position.x, this.position.y );
|
|
189
|
+
this.size.set( this.size.width, this.size.height );
|
|
190
|
+
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
//Force an update to set position/size
|
|
194
|
+
this.update();
|
|
195
|
+
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
export { ShadowMapViewer };
|