super-three 0.158.0 → 0.160.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 +1720 -380
- package/build/three.js +1720 -380
- package/build/three.min.js +1 -1
- package/build/three.module.js +1719 -381
- package/build/three.module.min.js +1 -1
- package/examples/jsm/Addons.js +2 -1
- package/examples/jsm/controls/OrbitControls.js +50 -40
- package/examples/jsm/csm/CSMShader.js +52 -47
- package/examples/jsm/exporters/GLTFExporter.js +79 -1
- package/examples/jsm/exporters/USDZExporter.js +27 -19
- package/examples/jsm/helpers/TextureHelper.js +237 -0
- package/examples/jsm/interactive/HTMLMesh.js +9 -2
- package/examples/jsm/lines/LineMaterial.js +16 -33
- package/examples/jsm/loaders/ColladaLoader.js +0 -6
- package/examples/jsm/loaders/DRACOLoader.js +4 -3
- package/examples/jsm/loaders/FBXLoader.js +294 -124
- package/examples/jsm/loaders/GLTFLoader.js +71 -3
- package/examples/jsm/loaders/MaterialXLoader.js +73 -54
- package/examples/jsm/loaders/NRRDLoader.js +0 -13
- package/examples/jsm/loaders/SVGLoader.js +4 -4
- package/examples/jsm/loaders/USDZLoader.js +3 -17
- package/examples/jsm/math/Octree.js +15 -4
- package/examples/jsm/misc/Timer.js +119 -0
- package/examples/jsm/misc/TubePainter.js +3 -6
- package/examples/jsm/modifiers/CurveModifier.js +20 -2
- package/examples/jsm/nodes/Nodes.js +11 -7
- package/examples/jsm/nodes/accessors/CameraNode.js +18 -2
- package/examples/jsm/nodes/accessors/CubeTextureNode.js +5 -73
- package/examples/jsm/nodes/accessors/MaterialReferenceNode.js +11 -2
- package/examples/jsm/nodes/accessors/ModelNode.js +1 -1
- package/examples/jsm/nodes/accessors/ModelViewProjectionNode.js +12 -3
- package/examples/jsm/nodes/accessors/MorphNode.js +191 -16
- package/examples/jsm/nodes/accessors/ReferenceNode.js +25 -1
- package/examples/jsm/nodes/accessors/TextureNode.js +122 -36
- package/examples/jsm/nodes/code/CodeNode.js +3 -3
- package/examples/jsm/nodes/core/AttributeNode.js +7 -1
- package/examples/jsm/nodes/core/CacheNode.js +4 -1
- package/examples/jsm/nodes/core/ConstNode.js +1 -1
- package/examples/jsm/nodes/core/Node.js +6 -3
- package/examples/jsm/nodes/core/NodeBuilder.js +84 -27
- package/examples/jsm/nodes/core/NodeFrame.js +10 -8
- package/examples/jsm/nodes/core/NodeUniform.js +12 -0
- package/examples/jsm/nodes/core/NodeUtils.js +3 -7
- package/examples/jsm/nodes/core/OutputStructNode.js +3 -3
- package/examples/jsm/nodes/core/PropertyNode.js +17 -2
- package/examples/jsm/nodes/core/StructTypeNode.js +4 -4
- package/examples/jsm/nodes/core/UniformGroup.js +13 -0
- package/examples/jsm/nodes/core/UniformGroupNode.js +36 -0
- package/examples/jsm/nodes/core/UniformNode.js +17 -0
- package/examples/jsm/nodes/core/VarNode.js +2 -0
- package/examples/jsm/nodes/core/VaryingNode.js +1 -7
- package/examples/jsm/nodes/display/BumpMapNode.js +1 -1
- package/examples/jsm/nodes/display/ColorAdjustmentNode.js +6 -10
- package/examples/jsm/nodes/display/GaussianBlurNode.js +170 -0
- package/examples/jsm/nodes/display/PassNode.js +182 -0
- package/examples/jsm/nodes/display/ViewportDepthNode.js +31 -3
- package/examples/jsm/nodes/display/ViewportDepthTextureNode.js +2 -2
- package/examples/jsm/nodes/display/ViewportNode.js +5 -8
- package/examples/jsm/nodes/functions/PhysicalLightingModel.js +1 -1
- package/examples/jsm/nodes/lighting/AnalyticLightNode.js +52 -17
- package/examples/jsm/nodes/lighting/EnvironmentNode.js +8 -12
- package/examples/jsm/nodes/lighting/LightsNode.js +34 -32
- package/examples/jsm/nodes/materials/InstancedPointsNodeMaterial.js +1 -1
- package/examples/jsm/nodes/materials/Line2NodeMaterial.js +12 -12
- package/examples/jsm/nodes/materials/MeshBasicNodeMaterial.js +1 -0
- package/examples/jsm/nodes/materials/MeshNormalNodeMaterial.js +1 -1
- package/examples/jsm/nodes/materials/NodeMaterial.js +66 -41
- package/examples/jsm/nodes/materials/PointsNodeMaterial.js +0 -10
- package/examples/jsm/nodes/materials/SpriteNodeMaterial.js +0 -7
- package/examples/jsm/nodes/materialx/MaterialXNodes.js +10 -10
- package/examples/jsm/nodes/materialx/lib/mx_hsv.js +128 -54
- package/examples/jsm/nodes/materialx/lib/mx_noise.js +1430 -618
- package/examples/jsm/nodes/materialx/lib/mx_transform_color.js +24 -14
- package/examples/jsm/nodes/math/MathNode.js +2 -0
- package/examples/jsm/nodes/math/OperatorNode.js +19 -6
- package/examples/jsm/nodes/shadernode/ShaderNode.js +32 -3
- package/examples/jsm/nodes/utils/FunctionOverloadingNode.js +95 -0
- package/examples/jsm/nodes/utils/RemapNode.js +2 -2
- package/examples/jsm/nodes/utils/SplitNode.js +8 -2
- package/examples/jsm/nodes/utils/TriplanarTexturesNode.js +3 -3
- package/examples/jsm/objects/QuadMesh.js +60 -0
- package/examples/jsm/postprocessing/GTAOPass.js +572 -0
- package/examples/jsm/postprocessing/OutputPass.js +2 -0
- package/examples/jsm/renderers/common/Animation.js +10 -21
- package/examples/jsm/renderers/common/Backend.js +19 -3
- package/examples/jsm/renderers/common/Background.js +20 -22
- package/examples/jsm/renderers/common/Bindings.js +30 -21
- package/examples/jsm/renderers/common/ChainMap.js +3 -3
- package/examples/jsm/renderers/common/Color4.js +37 -0
- package/examples/jsm/renderers/common/Geometries.js +4 -4
- package/examples/jsm/renderers/common/Info.js +12 -2
- package/examples/jsm/renderers/common/Pipelines.js +3 -51
- package/examples/jsm/renderers/common/PostProcessing.js +25 -0
- package/examples/jsm/renderers/common/RenderContext.js +1 -1
- package/examples/jsm/renderers/common/RenderContexts.js +1 -1
- package/examples/jsm/renderers/common/RenderObject.js +13 -1
- package/examples/jsm/renderers/common/RenderObjects.js +4 -2
- package/examples/jsm/renderers/common/Renderer.js +137 -37
- package/examples/jsm/renderers/common/StorageTexture.js +1 -0
- package/examples/jsm/renderers/common/Textures.js +4 -1
- package/examples/jsm/renderers/common/nodes/NodeBuilderState.js +10 -2
- package/examples/jsm/renderers/common/nodes/NodeUniformsGroup.js +44 -0
- package/examples/jsm/renderers/common/nodes/Nodes.js +74 -7
- package/examples/jsm/renderers/webgl/WebGLBackend.js +91 -33
- package/examples/jsm/renderers/webgl/nodes/GLSLNodeBuilder.js +100 -31
- package/examples/jsm/renderers/webgl/utils/WebGLAttributeUtils.js +57 -5
- package/examples/jsm/renderers/webgl/utils/WebGLCapabilities.js +36 -0
- package/examples/jsm/renderers/webgl/utils/WebGLExtensions.js +11 -1
- package/examples/jsm/renderers/webgl/utils/WebGLTextureUtils.js +71 -2
- package/examples/jsm/renderers/webgl/utils/WebGLUtils.js +42 -0
- package/examples/jsm/renderers/webgl-legacy/nodes/SlotNode.js +1 -1
- package/examples/jsm/renderers/webgl-legacy/nodes/WebGLNodeBuilder.js +33 -3
- package/examples/jsm/renderers/webgl-legacy/nodes/WebGLNodes.js +4 -14
- package/examples/jsm/renderers/webgpu/WebGPUBackend.js +186 -137
- package/examples/jsm/renderers/webgpu/WebGPURenderer.js +1 -1
- package/examples/jsm/renderers/webgpu/nodes/WGSLNodeBuilder.js +209 -90
- package/examples/jsm/renderers/webgpu/utils/WebGPUAttributeUtils.js +15 -10
- package/examples/jsm/renderers/webgpu/utils/WebGPUBindingUtils.js +11 -3
- package/examples/jsm/renderers/webgpu/utils/WebGPUPipelineUtils.js +2 -3
- package/examples/jsm/renderers/webgpu/utils/WebGPUTextureUtils.js +88 -6
- package/examples/jsm/shaders/FXAAShader.js +133 -133
- package/examples/jsm/shaders/GTAOShader.js +424 -0
- package/examples/jsm/shaders/OutputShader.js +4 -0
- package/examples/jsm/shaders/PoissonDenoiseShader.js +226 -0
- package/examples/jsm/shaders/SAOShader.js +2 -3
- package/examples/jsm/shaders/SSAOShader.js +2 -3
- package/examples/jsm/transpiler/AST.js +40 -1
- package/examples/jsm/transpiler/GLSLDecoder.js +50 -8
- package/examples/jsm/transpiler/ShaderToyDecoder.js +4 -4
- package/examples/jsm/transpiler/TSLEncoder.js +124 -20
- package/examples/jsm/utils/SortUtils.js +158 -0
- package/examples/jsm/utils/TextureUtils.js +33 -21
- package/examples/jsm/webxr/ARButton.js +14 -0
- package/examples/jsm/webxr/VRButton.js +23 -8
- package/examples/jsm/webxr/XRButton.js +25 -11
- package/package.json +5 -6
- package/src/Three.js +1 -0
- package/src/constants.js +2 -1
- package/src/core/BufferAttribute.js +21 -2
- package/src/core/InterleavedBuffer.js +21 -1
- package/src/core/Object3D.js +60 -12
- package/src/core/UniformsGroup.js +7 -1
- package/src/extras/curves/LineCurve3.js +4 -0
- package/src/loaders/AudioLoader.js +1 -1
- package/src/loaders/BufferGeometryLoader.js +0 -7
- package/src/loaders/ImageBitmapLoader.js +25 -1
- package/src/loaders/ObjectLoader.js +49 -0
- package/src/materials/ShaderMaterial.js +2 -1
- package/src/math/ColorManagement.js +0 -16
- package/src/math/Quaternion.js +5 -4
- package/src/math/Sphere.js +2 -0
- package/src/math/Triangle.js +17 -5
- package/src/objects/BatchedMesh.js +1020 -0
- package/src/objects/Skeleton.js +1 -3
- package/src/renderers/WebGL3DRenderTarget.js +2 -2
- package/src/renderers/WebGLArrayRenderTarget.js +2 -2
- package/src/renderers/WebGLRenderer.js +24 -19
- package/src/renderers/shaders/ShaderChunk/batching_pars_vertex.glsl.js +19 -0
- package/src/renderers/shaders/ShaderChunk/batching_vertex.glsl.js +5 -0
- package/src/renderers/shaders/ShaderChunk/cube_uv_reflection_fragment.glsl.js +0 -5
- package/src/renderers/shaders/ShaderChunk/defaultnormal_vertex.glsl.js +31 -4
- package/src/renderers/shaders/ShaderChunk/lights_physical_fragment.glsl.js +9 -4
- package/src/renderers/shaders/ShaderChunk/project_vertex.glsl.js +6 -0
- package/src/renderers/shaders/ShaderChunk/skinning_pars_vertex.glsl.js +9 -17
- package/src/renderers/shaders/ShaderChunk/tonemapping_pars_fragment.glsl.js +84 -0
- package/src/renderers/shaders/ShaderChunk/worldpos_vertex.glsl.js +6 -0
- package/src/renderers/shaders/ShaderChunk.js +4 -0
- package/src/renderers/shaders/ShaderLib/depth.glsl.js +2 -0
- package/src/renderers/shaders/ShaderLib/distanceRGBA.glsl.js +2 -0
- package/src/renderers/shaders/ShaderLib/meshbasic.glsl.js +2 -0
- package/src/renderers/shaders/ShaderLib/meshlambert.glsl.js +2 -0
- package/src/renderers/shaders/ShaderLib/meshmatcap.glsl.js +3 -0
- package/src/renderers/shaders/ShaderLib/meshnormal.glsl.js +2 -0
- package/src/renderers/shaders/ShaderLib/meshphong.glsl.js +2 -0
- package/src/renderers/shaders/ShaderLib/meshphysical.glsl.js +2 -0
- package/src/renderers/shaders/ShaderLib/meshtoon.glsl.js +2 -0
- package/src/renderers/shaders/ShaderLib/shadow.glsl.js +3 -0
- package/src/renderers/webgl/WebGLAttributes.js +39 -5
- package/src/renderers/webgl/WebGLBufferRenderer.js +31 -0
- package/src/renderers/webgl/WebGLCubeMaps.js +1 -1
- package/src/renderers/webgl/WebGLExtensions.js +1 -0
- package/src/renderers/webgl/WebGLIndexedBufferRenderer.js +31 -0
- package/src/renderers/webgl/WebGLLights.js +11 -2
- package/src/renderers/webgl/WebGLProgram.js +20 -1
- package/src/renderers/webgl/WebGLPrograms.js +5 -0
- package/src/renderers/webgl/WebGLShadowMap.js +35 -0
- package/src/renderers/webgl/WebGLTextures.js +7 -11
- package/src/renderers/webgl/WebGLUniforms.js +11 -1
- package/src/renderers/webgl/WebGLUniformsGroups.js +72 -93
- package/src/renderers/webxr/WebXRManager.js +16 -0
- package/examples/jsm/objects/BatchedMesh.js +0 -586
|
@@ -1,586 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
BufferAttribute,
|
|
3
|
-
BufferGeometry,
|
|
4
|
-
DataTexture,
|
|
5
|
-
FloatType,
|
|
6
|
-
MathUtils,
|
|
7
|
-
Matrix4,
|
|
8
|
-
Mesh,
|
|
9
|
-
RGBAFormat
|
|
10
|
-
} from 'three';
|
|
11
|
-
|
|
12
|
-
const ID_ATTR_NAME = '_batch_id_';
|
|
13
|
-
const _identityMatrix = new Matrix4();
|
|
14
|
-
const _zeroScaleMatrix = new Matrix4().set(
|
|
15
|
-
0, 0, 0, 0,
|
|
16
|
-
0, 0, 0, 0,
|
|
17
|
-
0, 0, 0, 0,
|
|
18
|
-
0, 0, 0, 1,
|
|
19
|
-
);
|
|
20
|
-
|
|
21
|
-
// Custom shaders
|
|
22
|
-
const batchingParsVertex = /* glsl */`
|
|
23
|
-
#ifdef BATCHING
|
|
24
|
-
attribute float ${ ID_ATTR_NAME };
|
|
25
|
-
uniform highp sampler2D batchingTexture;
|
|
26
|
-
uniform int batchingTextureSize;
|
|
27
|
-
mat4 getBatchingMatrix( const in float i ) {
|
|
28
|
-
float j = i * 4.0;
|
|
29
|
-
float x = mod( j, float( batchingTextureSize ) );
|
|
30
|
-
float y = floor( j / float( batchingTextureSize ) );
|
|
31
|
-
float dx = 1.0 / float( batchingTextureSize );
|
|
32
|
-
float dy = 1.0 / float( batchingTextureSize );
|
|
33
|
-
y = dy * ( y + 0.5 );
|
|
34
|
-
vec4 v1 = texture2D( batchingTexture, vec2( dx * ( x + 0.5 ), y ) );
|
|
35
|
-
vec4 v2 = texture2D( batchingTexture, vec2( dx * ( x + 1.5 ), y ) );
|
|
36
|
-
vec4 v3 = texture2D( batchingTexture, vec2( dx * ( x + 2.5 ), y ) );
|
|
37
|
-
vec4 v4 = texture2D( batchingTexture, vec2( dx * ( x + 3.5 ), y ) );
|
|
38
|
-
return mat4( v1, v2, v3, v4 );
|
|
39
|
-
}
|
|
40
|
-
#endif
|
|
41
|
-
`;
|
|
42
|
-
|
|
43
|
-
const batchingbaseVertex = /* glsl */`
|
|
44
|
-
#ifdef BATCHING
|
|
45
|
-
mat4 batchingMatrix = getBatchingMatrix( ${ ID_ATTR_NAME } );
|
|
46
|
-
#endif
|
|
47
|
-
`;
|
|
48
|
-
|
|
49
|
-
const batchingnormalVertex = /* glsl */`
|
|
50
|
-
#ifdef BATCHING
|
|
51
|
-
objectNormal = vec4( batchingMatrix * vec4( objectNormal, 0.0 ) ).xyz;
|
|
52
|
-
#ifdef USE_TANGENT
|
|
53
|
-
objectTangent = vec4( batchingMatrix * vec4( objectTangent, 0.0 ) ).xyz;
|
|
54
|
-
#endif
|
|
55
|
-
#endif
|
|
56
|
-
`;
|
|
57
|
-
|
|
58
|
-
const batchingVertex = /* glsl */`
|
|
59
|
-
#ifdef BATCHING
|
|
60
|
-
transformed = ( batchingMatrix * vec4( transformed, 1.0 ) ).xyz;
|
|
61
|
-
#endif
|
|
62
|
-
`;
|
|
63
|
-
|
|
64
|
-
// @TODO: SkinnedMesh support?
|
|
65
|
-
// @TODO: Future work if needed. Move into the core. Can be optimized more with WEBGL_multi_draw.
|
|
66
|
-
|
|
67
|
-
// copies data from attribute "src" into "target" starting at "targetOffset"
|
|
68
|
-
function copyAttributeData( src, target, targetOffset = 0 ) {
|
|
69
|
-
|
|
70
|
-
const itemSize = target.itemSize;
|
|
71
|
-
if ( src.isInterleavedBufferAttribute || src.array.constructor !== target.array.constructor ) {
|
|
72
|
-
|
|
73
|
-
// use the component getters and setters if the array data cannot
|
|
74
|
-
// be copied directly
|
|
75
|
-
const vertexCount = src.count;
|
|
76
|
-
for ( let i = 0; i < vertexCount; i ++ ) {
|
|
77
|
-
|
|
78
|
-
for ( let c = 0; c < itemSize; c ++ ) {
|
|
79
|
-
|
|
80
|
-
target.setComponent( i + targetOffset, c, src.getComponent( i, c ) );
|
|
81
|
-
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
} else {
|
|
87
|
-
|
|
88
|
-
// faster copy approach using typed array set function
|
|
89
|
-
target.array.set( src.array, targetOffset * itemSize );
|
|
90
|
-
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
target.needsUpdate = true;
|
|
94
|
-
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
class BatchedMesh extends Mesh {
|
|
98
|
-
|
|
99
|
-
constructor( maxGeometryCount, maxVertexCount, maxIndexCount = maxVertexCount * 2, material ) {
|
|
100
|
-
|
|
101
|
-
super( new BufferGeometry(), material );
|
|
102
|
-
|
|
103
|
-
this._vertexStarts = [];
|
|
104
|
-
this._vertexCounts = [];
|
|
105
|
-
this._indexStarts = [];
|
|
106
|
-
this._indexCounts = [];
|
|
107
|
-
|
|
108
|
-
this._visible = [];
|
|
109
|
-
this._active = [];
|
|
110
|
-
|
|
111
|
-
this._maxGeometryCount = maxGeometryCount;
|
|
112
|
-
this._maxVertexCount = maxVertexCount;
|
|
113
|
-
this._maxIndexCount = maxIndexCount;
|
|
114
|
-
|
|
115
|
-
this._geometryInitialized = false;
|
|
116
|
-
this._geometryCount = 0;
|
|
117
|
-
this._vertexCount = 0;
|
|
118
|
-
this._indexCount = 0;
|
|
119
|
-
|
|
120
|
-
// Local matrix per geometry by using data texture
|
|
121
|
-
// @TODO: Support uniform parameter per geometry
|
|
122
|
-
|
|
123
|
-
this._matrices = [];
|
|
124
|
-
this._matricesTexture = null;
|
|
125
|
-
|
|
126
|
-
// @TODO: Calculate the entire binding box and make frustumCulled true
|
|
127
|
-
this.frustumCulled = false;
|
|
128
|
-
|
|
129
|
-
this._customUniforms = {
|
|
130
|
-
batchingTexture: { value: null },
|
|
131
|
-
batchingTextureSize: { value: 0 }
|
|
132
|
-
};
|
|
133
|
-
|
|
134
|
-
this._initMatricesTexture();
|
|
135
|
-
this._initShader();
|
|
136
|
-
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
_initMatricesTexture() {
|
|
140
|
-
|
|
141
|
-
// layout (1 matrix = 4 pixels)
|
|
142
|
-
// RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
|
|
143
|
-
// with 8x8 pixel texture max 16 matrices * 4 pixels = (8 * 8)
|
|
144
|
-
// 16x16 pixel texture max 64 matrices * 4 pixels = (16 * 16)
|
|
145
|
-
// 32x32 pixel texture max 256 matrices * 4 pixels = (32 * 32)
|
|
146
|
-
// 64x64 pixel texture max 1024 matrices * 4 pixels = (64 * 64)
|
|
147
|
-
|
|
148
|
-
let size = Math.sqrt( this._maxGeometryCount * 4 ); // 4 pixels needed for 1 matrix
|
|
149
|
-
size = MathUtils.ceilPowerOfTwo( size );
|
|
150
|
-
size = Math.max( size, 4 );
|
|
151
|
-
|
|
152
|
-
const matricesArray = new Float32Array( size * size * 4 ); // 4 floats per RGBA pixel
|
|
153
|
-
const matricesTexture = new DataTexture( matricesArray, size, size, RGBAFormat, FloatType );
|
|
154
|
-
|
|
155
|
-
this._matricesTexture = matricesTexture;
|
|
156
|
-
this._customUniforms.batchingTexture.value = this._matricesTexture;
|
|
157
|
-
this._customUniforms.batchingTextureSize.value = size;
|
|
158
|
-
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
_initShader() {
|
|
162
|
-
|
|
163
|
-
const material = this.material;
|
|
164
|
-
const currentOnBeforeCompile = material.onBeforeCompile;
|
|
165
|
-
const customUniforms = this._customUniforms;
|
|
166
|
-
|
|
167
|
-
material.onBeforeCompile = function onBeforeCompile( parameters, renderer ) {
|
|
168
|
-
|
|
169
|
-
// Is this replacement stable across any materials?
|
|
170
|
-
parameters.vertexShader = parameters.vertexShader
|
|
171
|
-
.replace(
|
|
172
|
-
'#include <skinning_pars_vertex>',
|
|
173
|
-
'#include <skinning_pars_vertex>\n'
|
|
174
|
-
+ batchingParsVertex
|
|
175
|
-
)
|
|
176
|
-
.replace(
|
|
177
|
-
'#include <skinnormal_vertex>',
|
|
178
|
-
'#include <skinnormal_vertex>\n'
|
|
179
|
-
+ batchingbaseVertex
|
|
180
|
-
+ batchingnormalVertex
|
|
181
|
-
)
|
|
182
|
-
.replace(
|
|
183
|
-
'#include <skinning_vertex>',
|
|
184
|
-
'#include <skinning_vertex>\n'
|
|
185
|
-
+ batchingVertex
|
|
186
|
-
);
|
|
187
|
-
|
|
188
|
-
for ( const uniformName in customUniforms ) {
|
|
189
|
-
|
|
190
|
-
parameters.uniforms[ uniformName ] = customUniforms[ uniformName ];
|
|
191
|
-
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
currentOnBeforeCompile.call( this, parameters, renderer );
|
|
195
|
-
|
|
196
|
-
};
|
|
197
|
-
|
|
198
|
-
material.defines = material.defines || {};
|
|
199
|
-
material.defines.BATCHING = false;
|
|
200
|
-
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
_initializeGeometry( reference ) {
|
|
204
|
-
|
|
205
|
-
// @TODO: geometry.groups support?
|
|
206
|
-
// @TODO: geometry.drawRange support?
|
|
207
|
-
// @TODO: geometry.morphAttributes support?
|
|
208
|
-
|
|
209
|
-
const geometry = this.geometry;
|
|
210
|
-
const maxVertexCount = this._maxVertexCount;
|
|
211
|
-
const maxGeometryCount = this._maxGeometryCount;
|
|
212
|
-
const maxIndexCount = this._maxIndexCount;
|
|
213
|
-
if ( this._geometryInitialized === false ) {
|
|
214
|
-
|
|
215
|
-
for ( const attributeName in reference.attributes ) {
|
|
216
|
-
|
|
217
|
-
const srcAttribute = reference.getAttribute( attributeName );
|
|
218
|
-
const { array, itemSize, normalized } = srcAttribute;
|
|
219
|
-
|
|
220
|
-
const dstArray = new array.constructor( maxVertexCount * itemSize );
|
|
221
|
-
const dstAttribute = new srcAttribute.constructor( dstArray, itemSize, normalized );
|
|
222
|
-
dstAttribute.setUsage( srcAttribute.usage );
|
|
223
|
-
|
|
224
|
-
geometry.setAttribute( attributeName, dstAttribute );
|
|
225
|
-
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
if ( reference.getIndex() !== null ) {
|
|
229
|
-
|
|
230
|
-
const indexArray = maxVertexCount > 65536
|
|
231
|
-
? new Uint32Array( maxIndexCount )
|
|
232
|
-
: new Uint16Array( maxIndexCount );
|
|
233
|
-
|
|
234
|
-
geometry.setIndex( new BufferAttribute( indexArray, 1 ) );
|
|
235
|
-
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
const idArray = maxGeometryCount > 65536
|
|
239
|
-
? new Uint32Array( maxVertexCount )
|
|
240
|
-
: new Uint16Array( maxVertexCount );
|
|
241
|
-
geometry.setAttribute( ID_ATTR_NAME, new BufferAttribute( idArray, 1 ) );
|
|
242
|
-
|
|
243
|
-
this._geometryInitialized = true;
|
|
244
|
-
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
getGeometryCount() {
|
|
250
|
-
|
|
251
|
-
return this._geometryCount;
|
|
252
|
-
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
getVertexCount() {
|
|
256
|
-
|
|
257
|
-
return this._vertexCount;
|
|
258
|
-
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
getIndexCount() {
|
|
262
|
-
|
|
263
|
-
return this._indexCount;
|
|
264
|
-
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
applyGeometry( geometry ) {
|
|
268
|
-
|
|
269
|
-
this._initializeGeometry( geometry );
|
|
270
|
-
|
|
271
|
-
// ensure we're not over geometry
|
|
272
|
-
if ( this._geometryCount >= this._maxGeometryCount ) {
|
|
273
|
-
|
|
274
|
-
throw new Error( 'BatchedMesh: Maximum geometry count reached.' );
|
|
275
|
-
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
// check that the geometry doesn't have a version of our reserved id attribute
|
|
279
|
-
if ( geometry.getAttribute( ID_ATTR_NAME ) ) {
|
|
280
|
-
|
|
281
|
-
throw new Error( `BatchedMesh: Geometry cannot use attribute "${ ID_ATTR_NAME }"` );
|
|
282
|
-
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
// check to ensure the geometries are using consistent attributes and indices
|
|
286
|
-
const batchGeometry = this.geometry;
|
|
287
|
-
if ( Boolean( geometry.getIndex() ) !== Boolean( batchGeometry.getIndex() ) ) {
|
|
288
|
-
|
|
289
|
-
throw new Error( 'BatchedMesh: All geometries must consistently have "index".' );
|
|
290
|
-
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
for ( const attributeName in batchGeometry.attributes ) {
|
|
294
|
-
|
|
295
|
-
if ( attributeName === ID_ATTR_NAME ) {
|
|
296
|
-
|
|
297
|
-
continue;
|
|
298
|
-
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
if ( ! geometry.hasAttribute( attributeName ) ) {
|
|
302
|
-
|
|
303
|
-
throw new Error( `BatchedMesh: Added geometry missing "${ attributeName }". All geometries must have consistent attributes.` );
|
|
304
|
-
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
const srcAttribute = geometry.getAttribute( attributeName );
|
|
308
|
-
const dstAttribute = batchGeometry.getAttribute( attributeName );
|
|
309
|
-
if ( srcAttribute.itemSize !== dstAttribute.itemSize || srcAttribute.normalized !== dstAttribute.normalized ) {
|
|
310
|
-
|
|
311
|
-
throw new Error( 'BatchedMesh: All attributes must have a consistent itemSize and normalized value.' );
|
|
312
|
-
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
// Assuming geometry has position attribute
|
|
318
|
-
const srcPositionAttribute = geometry.getAttribute( 'position' );
|
|
319
|
-
const vertexCount = this._vertexCount;
|
|
320
|
-
const indexCount = this._indexCount;
|
|
321
|
-
const maxVertexCount = this._maxVertexCount;
|
|
322
|
-
const maxIndexCount = this._maxIndexCount;
|
|
323
|
-
|
|
324
|
-
// check if we're going over our maximum buffer capacity
|
|
325
|
-
if (
|
|
326
|
-
geometry.getIndex() !== null &&
|
|
327
|
-
indexCount + geometry.getIndex().count > maxIndexCount ||
|
|
328
|
-
vertexCount + srcPositionAttribute.count > maxVertexCount
|
|
329
|
-
) {
|
|
330
|
-
|
|
331
|
-
throw new Error( 'BatchedMesh: Added geometry is larger than available buffer capacity.' );
|
|
332
|
-
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
const visible = this._visible;
|
|
336
|
-
const active = this._active;
|
|
337
|
-
const matricesTexture = this._matricesTexture;
|
|
338
|
-
const matrices = this._matrices;
|
|
339
|
-
const matricesArray = this._matricesTexture.image.data;
|
|
340
|
-
|
|
341
|
-
const indexCounts = this._indexCounts;
|
|
342
|
-
const indexStarts = this._indexStarts;
|
|
343
|
-
const vertexCounts = this._vertexCounts;
|
|
344
|
-
const vertexStarts = this._vertexStarts;
|
|
345
|
-
|
|
346
|
-
const hasIndex = batchGeometry.getIndex() !== null;
|
|
347
|
-
const dstIndex = batchGeometry.getIndex();
|
|
348
|
-
const srcIndex = geometry.getIndex();
|
|
349
|
-
|
|
350
|
-
// push new geometry data range
|
|
351
|
-
vertexStarts.push( vertexCount );
|
|
352
|
-
vertexCounts.push( srcPositionAttribute.count );
|
|
353
|
-
|
|
354
|
-
// copy attribute data over
|
|
355
|
-
for ( const attributeName in batchGeometry.attributes ) {
|
|
356
|
-
|
|
357
|
-
if ( attributeName === ID_ATTR_NAME ) {
|
|
358
|
-
|
|
359
|
-
continue;
|
|
360
|
-
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
const srcAttribute = geometry.getAttribute( attributeName );
|
|
364
|
-
const dstAttribute = batchGeometry.getAttribute( attributeName );
|
|
365
|
-
copyAttributeData( srcAttribute, dstAttribute, vertexCount );
|
|
366
|
-
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
if ( hasIndex ) {
|
|
370
|
-
|
|
371
|
-
// push new index range
|
|
372
|
-
indexStarts.push( indexCount );
|
|
373
|
-
indexCounts.push( srcIndex.count );
|
|
374
|
-
|
|
375
|
-
// copy index data over
|
|
376
|
-
for ( let i = 0; i < srcIndex.count; i ++ ) {
|
|
377
|
-
|
|
378
|
-
dstIndex.setX( indexCount + i, vertexCount + srcIndex.getX( i ) );
|
|
379
|
-
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
this._indexCount += srcIndex.count;
|
|
383
|
-
dstIndex.needsUpdate = true;
|
|
384
|
-
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
// fill in the geometry ids
|
|
388
|
-
const geometryId = this._geometryCount;
|
|
389
|
-
this._geometryCount ++;
|
|
390
|
-
|
|
391
|
-
const idAttribute = batchGeometry.getAttribute( ID_ATTR_NAME );
|
|
392
|
-
for ( let i = 0; i < srcPositionAttribute.count; i ++ ) {
|
|
393
|
-
|
|
394
|
-
idAttribute.setX( this._vertexCount + i, geometryId );
|
|
395
|
-
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
idAttribute.needsUpdate = true;
|
|
399
|
-
|
|
400
|
-
// extend new range
|
|
401
|
-
this._vertexCount += srcPositionAttribute.count;
|
|
402
|
-
|
|
403
|
-
// push new visibility states
|
|
404
|
-
visible.push( true );
|
|
405
|
-
active.push( true );
|
|
406
|
-
|
|
407
|
-
// initialize matrix information
|
|
408
|
-
matrices.push( new Matrix4() );
|
|
409
|
-
_identityMatrix.toArray( matricesArray, geometryId * 16 );
|
|
410
|
-
matricesTexture.needsUpdate = true;
|
|
411
|
-
|
|
412
|
-
return geometryId;
|
|
413
|
-
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
deleteGeometry( geometryId ) {
|
|
417
|
-
|
|
418
|
-
// Note: User needs to call optimize() afterward to pack the data.
|
|
419
|
-
|
|
420
|
-
const active = this._active;
|
|
421
|
-
const matricesArray = this._matricesTexture.image.data;
|
|
422
|
-
const matricesTexture = this._matricesTexture;
|
|
423
|
-
if ( geometryId >= active.length || active[ geometryId ] === false ) {
|
|
424
|
-
|
|
425
|
-
return this;
|
|
426
|
-
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
active[ geometryId ] = false;
|
|
430
|
-
_zeroScaleMatrix.toArray( matricesArray, geometryId * 16 );
|
|
431
|
-
matricesTexture.needsUpdate = true;
|
|
432
|
-
|
|
433
|
-
return this;
|
|
434
|
-
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
optimize() {
|
|
438
|
-
|
|
439
|
-
throw new Error( 'BatchedMesh: Optimize function not implemented.' );
|
|
440
|
-
|
|
441
|
-
}
|
|
442
|
-
|
|
443
|
-
setMatrixAt( geometryId, matrix ) {
|
|
444
|
-
|
|
445
|
-
// @TODO: Map geometryId to index of the arrays because
|
|
446
|
-
// optimize() can make geometryId mismatch the index
|
|
447
|
-
|
|
448
|
-
const visible = this._visible;
|
|
449
|
-
const active = this._active;
|
|
450
|
-
const matricesTexture = this._matricesTexture;
|
|
451
|
-
const matrices = this._matrices;
|
|
452
|
-
const matricesArray = this._matricesTexture.image.data;
|
|
453
|
-
if ( geometryId >= matrices.length || active[ geometryId ] === false ) {
|
|
454
|
-
|
|
455
|
-
return this;
|
|
456
|
-
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
if ( visible[ geometryId ] === true ) {
|
|
460
|
-
|
|
461
|
-
matrix.toArray( matricesArray, geometryId * 16 );
|
|
462
|
-
matricesTexture.needsUpdate = true;
|
|
463
|
-
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
matrices[ geometryId ].copy( matrix );
|
|
467
|
-
|
|
468
|
-
return this;
|
|
469
|
-
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
getMatrixAt( geometryId, matrix ) {
|
|
473
|
-
|
|
474
|
-
const matrices = this._matrices;
|
|
475
|
-
const active = this._active;
|
|
476
|
-
if ( geometryId >= matrices.length || active[ geometryId ] === false ) {
|
|
477
|
-
|
|
478
|
-
return matrix;
|
|
479
|
-
|
|
480
|
-
}
|
|
481
|
-
|
|
482
|
-
return matrix.copy( matrices[ geometryId ] );
|
|
483
|
-
|
|
484
|
-
}
|
|
485
|
-
|
|
486
|
-
setVisibleAt( geometryId, value ) {
|
|
487
|
-
|
|
488
|
-
const visible = this._visible;
|
|
489
|
-
const active = this._active;
|
|
490
|
-
const matricesTexture = this._matricesTexture;
|
|
491
|
-
const matrices = this._matrices;
|
|
492
|
-
const matricesArray = this._matricesTexture.image.data;
|
|
493
|
-
|
|
494
|
-
// if the geometry is out of range, not active, or visibility state
|
|
495
|
-
// does not change then return early
|
|
496
|
-
if (
|
|
497
|
-
geometryId >= visible.length ||
|
|
498
|
-
active[ geometryId ] === false ||
|
|
499
|
-
visible[ geometryId ] === value
|
|
500
|
-
) {
|
|
501
|
-
|
|
502
|
-
return this;
|
|
503
|
-
|
|
504
|
-
}
|
|
505
|
-
|
|
506
|
-
// scale the matrix to zero if it's hidden
|
|
507
|
-
if ( value === true ) {
|
|
508
|
-
|
|
509
|
-
matrices[ geometryId ].toArray( matricesArray, geometryId * 16 );
|
|
510
|
-
|
|
511
|
-
} else {
|
|
512
|
-
|
|
513
|
-
_zeroScaleMatrix.toArray( matricesArray, geometryId * 16 );
|
|
514
|
-
|
|
515
|
-
}
|
|
516
|
-
|
|
517
|
-
matricesTexture.needsUpdate = true;
|
|
518
|
-
visible[ geometryId ] = value;
|
|
519
|
-
return this;
|
|
520
|
-
|
|
521
|
-
}
|
|
522
|
-
|
|
523
|
-
getVisibleAt( geometryId ) {
|
|
524
|
-
|
|
525
|
-
const visible = this._visible;
|
|
526
|
-
const active = this._active;
|
|
527
|
-
|
|
528
|
-
// return early if the geometry is out of range or not active
|
|
529
|
-
if ( geometryId >= visible.length || active[ geometryId ] === false ) {
|
|
530
|
-
|
|
531
|
-
return false;
|
|
532
|
-
|
|
533
|
-
}
|
|
534
|
-
|
|
535
|
-
return visible[ geometryId ];
|
|
536
|
-
|
|
537
|
-
}
|
|
538
|
-
|
|
539
|
-
raycast() {
|
|
540
|
-
|
|
541
|
-
console.warn( 'BatchedMesh: Raycast function not implemented.' );
|
|
542
|
-
|
|
543
|
-
}
|
|
544
|
-
|
|
545
|
-
copy() {
|
|
546
|
-
|
|
547
|
-
// super.copy( source );
|
|
548
|
-
|
|
549
|
-
throw new Error( 'BatchedMesh: Copy function not implemented.' );
|
|
550
|
-
|
|
551
|
-
}
|
|
552
|
-
|
|
553
|
-
toJSON() {
|
|
554
|
-
|
|
555
|
-
throw new Error( 'BatchedMesh: toJSON function not implemented.' );
|
|
556
|
-
|
|
557
|
-
}
|
|
558
|
-
|
|
559
|
-
dispose() {
|
|
560
|
-
|
|
561
|
-
// Assuming the geometry is not shared with other meshes
|
|
562
|
-
this.geometry.dispose();
|
|
563
|
-
|
|
564
|
-
this._matricesTexture.dispose();
|
|
565
|
-
this._matricesTexture = null;
|
|
566
|
-
return this;
|
|
567
|
-
|
|
568
|
-
}
|
|
569
|
-
|
|
570
|
-
onBeforeRender( _renderer, _scene, _camera, _geometry, material/*, _group*/ ) {
|
|
571
|
-
|
|
572
|
-
material.defines.BATCHING = true;
|
|
573
|
-
|
|
574
|
-
// @TODO: Implement frustum culling for each geometry
|
|
575
|
-
|
|
576
|
-
}
|
|
577
|
-
|
|
578
|
-
onAfterRender( _renderer, _scene, _camera, _geometry, material/*, _group*/ ) {
|
|
579
|
-
|
|
580
|
-
material.defines.BATCHING = false;
|
|
581
|
-
|
|
582
|
-
}
|
|
583
|
-
|
|
584
|
-
}
|
|
585
|
-
|
|
586
|
-
export { BatchedMesh };
|