three-stdlib 2.28.3 → 2.28.5
Sign up to get free protection for your applications and to get access to all the features.
- package/objects/BatchedMesh.cjs +261 -117
- package/objects/BatchedMesh.cjs.map +1 -1
- package/objects/BatchedMesh.d.ts +20 -10
- package/objects/BatchedMesh.js +261 -117
- package/objects/BatchedMesh.js.map +1 -1
- package/package.json +1 -1
- package/renderers/CSS3DRenderer.cjs +3 -6
- package/renderers/CSS3DRenderer.cjs.map +1 -1
- package/renderers/CSS3DRenderer.js +3 -6
- package/renderers/CSS3DRenderer.js.map +1 -1
package/objects/BatchedMesh.cjs
CHANGED
@@ -7,27 +7,27 @@ var __publicField = (obj, key, value) => {
|
|
7
7
|
};
|
8
8
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
9
9
|
const THREE = require("three");
|
10
|
+
const ID_ATTR_NAME = "_batch_id_";
|
10
11
|
const _identityMatrix = new THREE.Matrix4();
|
11
12
|
const _zeroScaleMatrix = new THREE.Matrix4().set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1);
|
12
13
|
const batchingParsVertex = (
|
13
14
|
/* glsl */
|
14
15
|
`
|
15
16
|
#ifdef BATCHING
|
16
|
-
attribute float
|
17
|
+
attribute float ${ID_ATTR_NAME};
|
17
18
|
uniform highp sampler2D batchingTexture;
|
18
|
-
uniform int batchingTextureSize;
|
19
19
|
mat4 getBatchingMatrix( const in float i ) {
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
vec4
|
27
|
-
vec4
|
28
|
-
vec4
|
29
|
-
vec4 v4 = texture2D( batchingTexture, vec2( dx * ( x + 3.5 ), y ) );
|
20
|
+
|
21
|
+
int size = textureSize( batchingTexture, 0 ).x;
|
22
|
+
int j = int( i ) * 4;
|
23
|
+
int x = j % size;
|
24
|
+
int y = j / size;
|
25
|
+
vec4 v1 = texelFetch( batchingTexture, ivec2( x, y ), 0 );
|
26
|
+
vec4 v2 = texelFetch( batchingTexture, ivec2( x + 1, y ), 0 );
|
27
|
+
vec4 v3 = texelFetch( batchingTexture, ivec2( x + 2, y ), 0 );
|
28
|
+
vec4 v4 = texelFetch( batchingTexture, ivec2( x + 3, y ), 0 );
|
30
29
|
return mat4( v1, v2, v3, v4 );
|
30
|
+
|
31
31
|
}
|
32
32
|
#endif
|
33
33
|
`
|
@@ -36,7 +36,7 @@ const batchingbaseVertex = (
|
|
36
36
|
/* glsl */
|
37
37
|
`
|
38
38
|
#ifdef BATCHING
|
39
|
-
mat4 batchingMatrix = getBatchingMatrix(
|
39
|
+
mat4 batchingMatrix = getBatchingMatrix( ${ID_ATTR_NAME} );
|
40
40
|
#endif
|
41
41
|
`
|
42
42
|
);
|
@@ -59,6 +59,20 @@ const batchingVertex = (
|
|
59
59
|
#endif
|
60
60
|
`
|
61
61
|
);
|
62
|
+
function copyAttributeData(src, target, targetOffset = 0) {
|
63
|
+
const itemSize = target.itemSize;
|
64
|
+
if (src.isInterleavedBufferAttribute || src.array.constructor !== target.array.constructor) {
|
65
|
+
const vertexCount = src.count;
|
66
|
+
for (let i = 0; i < vertexCount; i++) {
|
67
|
+
for (let c = 0; c < itemSize; c++) {
|
68
|
+
target.setComponent(i + targetOffset, c, src.getComponent(i, c));
|
69
|
+
}
|
70
|
+
}
|
71
|
+
} else {
|
72
|
+
target.array.set(src.array, targetOffset * itemSize);
|
73
|
+
}
|
74
|
+
target.needsUpdate = true;
|
75
|
+
}
|
62
76
|
class BatchedMesh extends THREE.Mesh {
|
63
77
|
constructor(maxGeometryCount, maxVertexCount, maxIndexCount = maxVertexCount * 2, material) {
|
64
78
|
super(new THREE.BufferGeometry(), material);
|
@@ -66,41 +80,34 @@ class BatchedMesh extends THREE.Mesh {
|
|
66
80
|
__publicField(this, "_vertexCounts");
|
67
81
|
__publicField(this, "_indexStarts");
|
68
82
|
__publicField(this, "_indexCounts");
|
69
|
-
__publicField(this, "
|
70
|
-
__publicField(this, "
|
83
|
+
__publicField(this, "_reservedRanges");
|
84
|
+
__publicField(this, "_visible");
|
85
|
+
__publicField(this, "_active");
|
71
86
|
__publicField(this, "_maxGeometryCount");
|
72
87
|
__publicField(this, "_maxVertexCount");
|
73
88
|
__publicField(this, "_maxIndexCount");
|
74
89
|
__publicField(this, "_geometryInitialized");
|
75
90
|
__publicField(this, "_geometryCount");
|
76
|
-
__publicField(this, "_vertexCount");
|
77
|
-
__publicField(this, "_indexCount");
|
78
91
|
__publicField(this, "_matrices");
|
79
|
-
__publicField(this, "_matricesArray");
|
80
92
|
__publicField(this, "_matricesTexture");
|
81
|
-
__publicField(this, "_matricesTextureSize");
|
82
93
|
__publicField(this, "_customUniforms");
|
83
94
|
this._vertexStarts = [];
|
84
95
|
this._vertexCounts = [];
|
85
96
|
this._indexStarts = [];
|
86
97
|
this._indexCounts = [];
|
87
|
-
this.
|
88
|
-
this.
|
98
|
+
this._reservedRanges = [];
|
99
|
+
this._visible = [];
|
100
|
+
this._active = [];
|
89
101
|
this._maxGeometryCount = maxGeometryCount;
|
90
102
|
this._maxVertexCount = maxVertexCount;
|
91
103
|
this._maxIndexCount = maxIndexCount;
|
92
104
|
this._geometryInitialized = false;
|
93
105
|
this._geometryCount = 0;
|
94
|
-
this._vertexCount = 0;
|
95
|
-
this._indexCount = 0;
|
96
106
|
this._matrices = [];
|
97
|
-
this._matricesArray = null;
|
98
107
|
this._matricesTexture = null;
|
99
|
-
this._matricesTextureSize = null;
|
100
108
|
this.frustumCulled = false;
|
101
109
|
this._customUniforms = {
|
102
|
-
batchingTexture: { value: null }
|
103
|
-
batchingTextureSize: { value: 0 }
|
110
|
+
batchingTexture: { value: null }
|
104
111
|
};
|
105
112
|
this._initMatricesTexture();
|
106
113
|
this._initShader();
|
@@ -121,158 +128,295 @@ class BatchedMesh extends THREE.Mesh {
|
|
121
128
|
size = Math.max(size, 4);
|
122
129
|
const matricesArray = new Float32Array(size * size * 4);
|
123
130
|
const matricesTexture = new THREE.DataTexture(matricesArray, size, size, THREE.RGBAFormat, THREE.FloatType);
|
124
|
-
this._matricesArray = matricesArray;
|
125
131
|
this._matricesTexture = matricesTexture;
|
126
|
-
this._matricesTextureSize = size;
|
127
132
|
this._customUniforms.batchingTexture.value = this._matricesTexture;
|
128
|
-
this._customUniforms.batchingTextureSize.value = this._matricesTextureSize;
|
129
133
|
}
|
130
134
|
_initShader() {
|
131
|
-
const
|
135
|
+
const material = this.material;
|
136
|
+
const currentOnBeforeCompile = material.onBeforeCompile;
|
132
137
|
const customUniforms = this._customUniforms;
|
133
|
-
|
134
|
-
parameters.vertexShader = parameters.vertexShader.replace("#include <skinning_pars_vertex>", "#include <skinning_pars_vertex>\n" + batchingParsVertex).replace(
|
135
|
-
"#include <skinnormal_vertex>",
|
136
|
-
"#include <skinnormal_vertex>\n" + batchingbaseVertex + batchingnormalVertex
|
137
|
-
).replace("#include <skinning_vertex>", "#include <skinning_vertex>\n" + batchingVertex);
|
138
|
+
material.onBeforeCompile = function onBeforeCompile(parameters, renderer) {
|
139
|
+
parameters.vertexShader = parameters.vertexShader.replace("#include <skinning_pars_vertex>", "#include <skinning_pars_vertex>\n" + batchingParsVertex).replace("#include <uv_vertex>", "#include <uv_vertex>\n" + batchingbaseVertex).replace("#include <skinnormal_vertex>", "#include <skinnormal_vertex>\n" + batchingnormalVertex).replace("#include <skinning_vertex>", "#include <skinning_vertex>\n" + batchingVertex);
|
138
140
|
for (const uniformName in customUniforms) {
|
139
141
|
parameters.uniforms[uniformName] = customUniforms[uniformName];
|
140
142
|
}
|
141
143
|
currentOnBeforeCompile.call(this, parameters, renderer);
|
142
144
|
};
|
143
|
-
|
144
|
-
|
145
|
+
material.defines = material.defines || {};
|
146
|
+
material.defines.BATCHING = false;
|
147
|
+
}
|
148
|
+
_initializeGeometry(reference) {
|
149
|
+
const geometry = this.geometry;
|
150
|
+
const maxVertexCount = this._maxVertexCount;
|
151
|
+
const maxGeometryCount = this._maxGeometryCount;
|
152
|
+
const maxIndexCount = this._maxIndexCount;
|
153
|
+
if (this._geometryInitialized === false) {
|
154
|
+
for (const attributeName in reference.attributes) {
|
155
|
+
const srcAttribute = reference.getAttribute(attributeName);
|
156
|
+
const { array, itemSize, normalized } = srcAttribute;
|
157
|
+
const dstArray = new array.constructor(maxVertexCount * itemSize);
|
158
|
+
const dstAttribute = new srcAttribute.constructor(dstArray, itemSize, normalized);
|
159
|
+
dstAttribute.setUsage(srcAttribute.usage);
|
160
|
+
geometry.setAttribute(attributeName, dstAttribute);
|
161
|
+
}
|
162
|
+
if (reference.getIndex() !== null) {
|
163
|
+
const indexArray = maxVertexCount > 65536 ? new Uint32Array(maxIndexCount) : new Uint16Array(maxIndexCount);
|
164
|
+
geometry.setIndex(new THREE.BufferAttribute(indexArray, 1));
|
165
|
+
}
|
166
|
+
const idArray = maxGeometryCount > 65536 ? new Uint32Array(maxVertexCount) : new Uint16Array(maxVertexCount);
|
167
|
+
geometry.setAttribute(ID_ATTR_NAME, new THREE.BufferAttribute(idArray, 1));
|
168
|
+
this._geometryInitialized = true;
|
169
|
+
}
|
170
|
+
}
|
171
|
+
// Make sure the geometry is compatible with the existing combined geometry atributes
|
172
|
+
_validateGeometry(geometry) {
|
173
|
+
if (geometry.getAttribute(ID_ATTR_NAME)) {
|
174
|
+
throw new Error(`BatchedMesh: Geometry cannot use attribute "${ID_ATTR_NAME}"`);
|
175
|
+
}
|
176
|
+
const batchGeometry = this.geometry;
|
177
|
+
if (Boolean(geometry.getIndex()) !== Boolean(batchGeometry.getIndex())) {
|
178
|
+
throw new Error('BatchedMesh: All geometries must consistently have "index".');
|
179
|
+
}
|
180
|
+
for (const attributeName in batchGeometry.attributes) {
|
181
|
+
if (attributeName === ID_ATTR_NAME) {
|
182
|
+
continue;
|
183
|
+
}
|
184
|
+
if (!geometry.hasAttribute(attributeName)) {
|
185
|
+
throw new Error(
|
186
|
+
`BatchedMesh: Added geometry missing "${attributeName}". All geometries must have consistent attributes.`
|
187
|
+
);
|
188
|
+
}
|
189
|
+
const srcAttribute = geometry.getAttribute(attributeName);
|
190
|
+
const dstAttribute = batchGeometry.getAttribute(attributeName);
|
191
|
+
if (srcAttribute.itemSize !== dstAttribute.itemSize || srcAttribute.normalized !== dstAttribute.normalized) {
|
192
|
+
throw new Error("BatchedMesh: All attributes must have a consistent itemSize and normalized value.");
|
193
|
+
}
|
194
|
+
}
|
145
195
|
}
|
146
196
|
getGeometryCount() {
|
147
197
|
return this._geometryCount;
|
148
198
|
}
|
149
199
|
getVertexCount() {
|
150
|
-
|
200
|
+
const reservedRanges = this._reservedRanges;
|
201
|
+
if (reservedRanges.length === 0) {
|
202
|
+
return 0;
|
203
|
+
} else {
|
204
|
+
const finalRange = reservedRanges[reservedRanges.length - 1];
|
205
|
+
return finalRange.vertexStart + finalRange.vertexCount;
|
206
|
+
}
|
151
207
|
}
|
152
208
|
getIndexCount() {
|
153
|
-
|
209
|
+
const reservedRanges = this._reservedRanges;
|
210
|
+
const geometry = this.geometry;
|
211
|
+
if (geometry.getIndex() === null || reservedRanges.length === 0) {
|
212
|
+
return 0;
|
213
|
+
} else {
|
214
|
+
const finalRange = reservedRanges[reservedRanges.length - 1];
|
215
|
+
return finalRange.indexStart + finalRange.indexCount;
|
216
|
+
}
|
154
217
|
}
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
218
|
+
addGeometry(geometry, vertexCount = -1, indexCount = -1) {
|
219
|
+
this._initializeGeometry(geometry);
|
220
|
+
this._validateGeometry(geometry);
|
221
|
+
if (this._geometryCount >= this._maxGeometryCount) {
|
222
|
+
throw new Error("BatchedMesh: Maximum geometry count reached.");
|
223
|
+
}
|
224
|
+
const range = {
|
225
|
+
vertexStart: -1,
|
226
|
+
vertexCount: -1,
|
227
|
+
indexStart: -1,
|
228
|
+
indexCount: -1
|
229
|
+
};
|
230
|
+
let lastRange = null;
|
231
|
+
const reservedRanges = this._reservedRanges;
|
232
|
+
if (this._geometryCount !== 0) {
|
233
|
+
lastRange = reservedRanges[reservedRanges.length - 1];
|
234
|
+
}
|
235
|
+
if (vertexCount === -1) {
|
236
|
+
range.vertexCount = geometry.getAttribute("position").count;
|
237
|
+
} else {
|
238
|
+
range.vertexCount = vertexCount;
|
239
|
+
}
|
240
|
+
if (lastRange === null) {
|
241
|
+
range.vertexStart = 0;
|
242
|
+
} else {
|
243
|
+
range.vertexStart = lastRange.vertexStart + lastRange.vertexCount;
|
244
|
+
}
|
245
|
+
if (geometry.getIndex() !== null) {
|
246
|
+
if (indexCount === -1) {
|
247
|
+
range.indexCount = geometry.getIndex().count;
|
248
|
+
} else {
|
249
|
+
range.indexCount = indexCount;
|
167
250
|
}
|
168
|
-
if (
|
169
|
-
|
170
|
-
|
251
|
+
if (lastRange === null) {
|
252
|
+
range.indexStart = 0;
|
253
|
+
} else {
|
254
|
+
range.indexStart = lastRange.indexStart + lastRange.indexCount;
|
171
255
|
}
|
172
|
-
const idArray = this._maxGeometryCount > 65536 ? new Uint32Array(this._maxVertexCount) : new Uint16Array(this._maxVertexCount);
|
173
|
-
this.geometry.setAttribute("id", new THREE.BufferAttribute(idArray, 1));
|
174
|
-
this._geometryInitialized = true;
|
175
256
|
}
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
const
|
180
|
-
this.
|
181
|
-
this._vertexCounts
|
182
|
-
|
183
|
-
|
184
|
-
|
257
|
+
if (range.indexStart !== -1 && range.indexStart + range.indexCount > this._maxIndexCount || range.vertexStart + range.vertexCount > this._maxVertexCount) {
|
258
|
+
throw new Error("BatchedMesh: Reserved space request exceeds the maximum buffer size.");
|
259
|
+
}
|
260
|
+
const indexCounts = this._indexCounts;
|
261
|
+
const indexStarts = this._indexStarts;
|
262
|
+
const vertexCounts = this._vertexCounts;
|
263
|
+
const vertexStarts = this._vertexStarts;
|
264
|
+
const visible = this._visible;
|
265
|
+
const active = this._active;
|
266
|
+
const matricesTexture = this._matricesTexture;
|
267
|
+
const matrices = this._matrices;
|
268
|
+
const matricesArray = this._matricesTexture.image.data;
|
269
|
+
visible.push(true);
|
270
|
+
active.push(true);
|
271
|
+
const geometryId = this._geometryCount;
|
272
|
+
this._geometryCount++;
|
273
|
+
matrices.push(new THREE.Matrix4());
|
274
|
+
_identityMatrix.toArray(matricesArray, geometryId * 16);
|
275
|
+
matricesTexture.needsUpdate = true;
|
276
|
+
reservedRanges.push(range);
|
277
|
+
vertexStarts.push(range.vertexStart);
|
278
|
+
vertexCounts.push(range.vertexCount);
|
279
|
+
if (geometry.getIndex() !== null) {
|
280
|
+
indexStarts.push(range.indexCount);
|
281
|
+
indexCounts.push(range.indexCount);
|
282
|
+
}
|
283
|
+
const idAttribute = this.geometry.getAttribute(ID_ATTR_NAME);
|
284
|
+
for (let i = 0; i < range.vertexCount; i++) {
|
285
|
+
idAttribute.setX(range.vertexStart + i, geometryId);
|
286
|
+
}
|
287
|
+
idAttribute.needsUpdate = true;
|
288
|
+
this.setGeometryAt(geometryId, geometry);
|
289
|
+
return geometryId;
|
290
|
+
}
|
291
|
+
/**
|
292
|
+
* @deprecated use `addGeometry` instead.
|
293
|
+
*/
|
294
|
+
applyGeometry(geometry) {
|
295
|
+
return this.addGeometry(geometry);
|
296
|
+
}
|
297
|
+
setGeometryAt(id, geometry) {
|
298
|
+
if (id >= this._geometryCount) {
|
299
|
+
throw new Error("BatchedMesh: Maximum geometry count reached.");
|
185
300
|
}
|
186
|
-
this.
|
187
|
-
this.
|
188
|
-
|
301
|
+
this._validateGeometry(geometry);
|
302
|
+
const range = this._reservedRanges[id];
|
303
|
+
if (geometry.getIndex() !== null && geometry.getIndex().count > range.indexCount || geometry.attributes.position.count > range.vertexCount) {
|
304
|
+
throw new Error("BatchedMesh: Reserved space not large enough for provided geometry.");
|
305
|
+
}
|
306
|
+
const batchGeometry = this.geometry;
|
307
|
+
const srcPositionAttribute = geometry.getAttribute("position");
|
308
|
+
const hasIndex = batchGeometry.getIndex() !== null;
|
309
|
+
const dstIndex = batchGeometry.getIndex();
|
310
|
+
const srcIndex = geometry.getIndex();
|
311
|
+
const vertexStart = range.vertexStart;
|
312
|
+
const vertexCount = range.vertexCount;
|
313
|
+
for (const attributeName in batchGeometry.attributes) {
|
314
|
+
if (attributeName === ID_ATTR_NAME) {
|
315
|
+
continue;
|
316
|
+
}
|
189
317
|
const srcAttribute = geometry.getAttribute(attributeName);
|
190
|
-
const dstAttribute =
|
191
|
-
|
318
|
+
const dstAttribute = batchGeometry.getAttribute(attributeName);
|
319
|
+
copyAttributeData(srcAttribute, dstAttribute, vertexStart);
|
320
|
+
const itemSize = srcAttribute.itemSize;
|
321
|
+
for (let i = srcAttribute.count, l = vertexCount; i < l; i++) {
|
322
|
+
const index = vertexStart + i;
|
323
|
+
for (let c = 0; c < itemSize; c++) {
|
324
|
+
dstAttribute.setComponent(index, c, 0);
|
325
|
+
}
|
326
|
+
}
|
192
327
|
dstAttribute.needsUpdate = true;
|
193
328
|
}
|
329
|
+
this._vertexCounts[id] = srcPositionAttribute.count;
|
194
330
|
if (hasIndex) {
|
331
|
+
const indexStart = range.indexStart;
|
195
332
|
for (let i = 0; i < srcIndex.count; i++) {
|
196
|
-
dstIndex.setX(
|
333
|
+
dstIndex.setX(indexStart + i, vertexStart + srcIndex.getX(i));
|
334
|
+
}
|
335
|
+
for (let i = srcIndex.count, l = range.indexCount; i < l; i++) {
|
336
|
+
dstIndex.setX(indexStart + i, vertexStart);
|
197
337
|
}
|
198
|
-
this._indexCount += srcIndex.count;
|
199
338
|
dstIndex.needsUpdate = true;
|
339
|
+
this._indexCounts[id] = srcIndex.count;
|
200
340
|
}
|
201
|
-
|
202
|
-
this._geometryCount++;
|
203
|
-
const idAttribute = this.geometry.getAttribute("id");
|
204
|
-
for (let i = 0; i < srcPositionAttribute.count; i++) {
|
205
|
-
idAttribute.setX(this._vertexCount + i, geometryId);
|
206
|
-
}
|
207
|
-
idAttribute.needsUpdate = true;
|
208
|
-
this._vertexCount += srcPositionAttribute.count;
|
209
|
-
this._matrices.push(new THREE.Matrix4());
|
210
|
-
_identityMatrix.toArray((_a = this._matricesArray) != null ? _a : void 0, geometryId * 16);
|
211
|
-
this._matricesTexture.needsUpdate = true;
|
212
|
-
return geometryId;
|
341
|
+
return id;
|
213
342
|
}
|
214
343
|
deleteGeometry(geometryId) {
|
215
|
-
|
344
|
+
const active = this._active;
|
345
|
+
const matricesTexture = this._matricesTexture;
|
346
|
+
const matricesArray = matricesTexture.image.data;
|
347
|
+
if (geometryId >= active.length || active[geometryId] === false) {
|
216
348
|
return this;
|
217
349
|
}
|
218
|
-
|
219
|
-
_zeroScaleMatrix.toArray(
|
220
|
-
|
350
|
+
active[geometryId] = false;
|
351
|
+
_zeroScaleMatrix.toArray(matricesArray, geometryId * 16);
|
352
|
+
matricesTexture.needsUpdate = true;
|
221
353
|
return this;
|
222
354
|
}
|
223
355
|
optimize() {
|
224
|
-
|
356
|
+
throw new Error("BatchedMesh: Optimize function not implemented.");
|
225
357
|
}
|
226
358
|
setMatrixAt(geometryId, matrix) {
|
227
|
-
|
359
|
+
const visible = this._visible;
|
360
|
+
const active = this._active;
|
361
|
+
const matricesTexture = this._matricesTexture;
|
362
|
+
const matrices = this._matrices;
|
363
|
+
const matricesArray = matricesTexture.image.data;
|
364
|
+
if (geometryId >= matrices.length || active[geometryId] === false) {
|
228
365
|
return this;
|
229
366
|
}
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
this._matricesTexture.needsUpdate = true;
|
367
|
+
if (visible[geometryId] === true) {
|
368
|
+
matrix.toArray(matricesArray, geometryId * 16);
|
369
|
+
matricesTexture.needsUpdate = true;
|
234
370
|
}
|
371
|
+
matrices[geometryId].copy(matrix);
|
235
372
|
return this;
|
236
373
|
}
|
237
374
|
getMatrixAt(geometryId, matrix) {
|
238
|
-
|
375
|
+
const matrices = this._matrices;
|
376
|
+
const active = this._active;
|
377
|
+
if (geometryId >= matrices.length || active[geometryId] === false) {
|
239
378
|
return matrix;
|
240
379
|
}
|
241
|
-
return matrix.copy(
|
380
|
+
return matrix.copy(matrices[geometryId]);
|
242
381
|
}
|
243
|
-
setVisibleAt(geometryId,
|
244
|
-
|
382
|
+
setVisibleAt(geometryId, value) {
|
383
|
+
const visible = this._visible;
|
384
|
+
const active = this._active;
|
385
|
+
const matricesTexture = this._matricesTexture;
|
386
|
+
const matrices = this._matrices;
|
387
|
+
const matricesArray = matricesTexture.image.data;
|
388
|
+
if (geometryId >= visible.length || active[geometryId] === false || visible[geometryId] === value) {
|
245
389
|
return this;
|
246
390
|
}
|
247
|
-
if (
|
248
|
-
|
249
|
-
}
|
250
|
-
if (visible === true) {
|
251
|
-
this._matrices[geometryId].toArray(this._matricesArray, geometryId * 16);
|
391
|
+
if (value === true) {
|
392
|
+
matrices[geometryId].toArray(matricesArray, geometryId * 16);
|
252
393
|
} else {
|
253
|
-
_zeroScaleMatrix.toArray(
|
394
|
+
_zeroScaleMatrix.toArray(matricesArray, geometryId * 16);
|
254
395
|
}
|
255
|
-
|
256
|
-
|
396
|
+
matricesTexture.needsUpdate = true;
|
397
|
+
visible[geometryId] = value;
|
257
398
|
return this;
|
258
399
|
}
|
259
400
|
getVisibleAt(geometryId) {
|
260
|
-
|
401
|
+
const visible = this._visible;
|
402
|
+
const active = this._active;
|
403
|
+
if (geometryId >= visible.length || active[geometryId] === false) {
|
261
404
|
return false;
|
262
405
|
}
|
263
|
-
return
|
406
|
+
return visible[geometryId];
|
264
407
|
}
|
265
|
-
|
266
|
-
|
267
|
-
|
408
|
+
raycast() {
|
409
|
+
console.warn("BatchedMesh: Raycast function not implemented.");
|
410
|
+
}
|
411
|
+
copy() {
|
412
|
+
throw new Error("BatchedMesh: Copy function not implemented.");
|
268
413
|
}
|
269
|
-
toJSON(
|
270
|
-
|
414
|
+
toJSON() {
|
415
|
+
throw new Error("BatchedMesh: toJSON function not implemented.");
|
271
416
|
}
|
272
417
|
dispose() {
|
273
|
-
var _a;
|
274
418
|
this.geometry.dispose();
|
275
|
-
|
419
|
+
this._matricesTexture.dispose();
|
276
420
|
this._matricesTexture = null;
|
277
421
|
return this;
|
278
422
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"BatchedMesh.cjs","sources":["../../src/objects/BatchedMesh.ts"],"sourcesContent":["import {\n Matrix4,\n Mesh,\n BufferGeometry,\n Material,\n DataTexture,\n IUniform,\n MathUtils,\n RGBAFormat,\n FloatType,\n BufferAttribute,\n} from 'three'\n\nconst _identityMatrix = new Matrix4()\nconst _zeroScaleMatrix = new Matrix4().set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1)\n\n// Custom shaders\nconst batchingParsVertex = /* glsl */ `\n#ifdef BATCHING\n\tattribute float id;\n\tuniform highp sampler2D batchingTexture;\n\tuniform int batchingTextureSize;\n\tmat4 getBatchingMatrix( const in float i ) {\n\t\tfloat j = i * 4.0;\n\t\tfloat x = mod( j, float( batchingTextureSize ) );\n\t\tfloat y = floor( j / float( batchingTextureSize ) );\n\t\tfloat dx = 1.0 / float( batchingTextureSize );\n\t\tfloat dy = 1.0 / float( batchingTextureSize );\n\t\ty = dy * ( y + 0.5 );\n\t\tvec4 v1 = texture2D( batchingTexture, vec2( dx * ( x + 0.5 ), y ) );\n\t\tvec4 v2 = texture2D( batchingTexture, vec2( dx * ( x + 1.5 ), y ) );\n\t\tvec4 v3 = texture2D( batchingTexture, vec2( dx * ( x + 2.5 ), y ) );\n\t\tvec4 v4 = texture2D( batchingTexture, vec2( dx * ( x + 3.5 ), y ) );\n\t\treturn mat4( v1, v2, v3, v4 );\n\t}\n#endif\n`\n\nconst batchingbaseVertex = /* glsl */ `\n#ifdef BATCHING\n\tmat4 batchingMatrix = getBatchingMatrix( id );\n#endif\n`\n\nconst batchingnormalVertex = /* glsl */ `\n#ifdef BATCHING\n\tobjectNormal = vec4( batchingMatrix * vec4( objectNormal, 0.0 ) ).xyz;\n\t#ifdef USE_TANGENT\n\t\tobjectTangent = vec4( batchingMatrix * vec4( objectTangent, 0.0 ) ).xyz;\n\t#endif\n#endif\n`\n\nconst batchingVertex = /* glsl */ `\n#ifdef BATCHING\n\ttransformed = ( batchingMatrix * vec4( transformed, 1.0 ) ).xyz;\n#endif\n`\n\n// @TODO: SkinnedMesh support?\n// @TODO: Future work if needed. Move into the core. Can be optimized more with WEBGL_multi_draw.\n\nclass BatchedMesh extends Mesh<BufferGeometry, Material> {\n _vertexStarts: number[]\n _vertexCounts: number[]\n _indexStarts: number[]\n _indexCounts: number[]\n _visibles: boolean[]\n _alives: boolean[]\n _maxGeometryCount: number\n _maxVertexCount: number\n _maxIndexCount: number\n _geometryInitialized: boolean\n _geometryCount: number\n _vertexCount: number\n _indexCount: number\n _matrices: Matrix4[]\n _matricesArray: Float32Array | null\n _matricesTexture: DataTexture | null\n _matricesTextureSize: number | null\n _customUniforms: Record<string, IUniform>\n\n constructor(\n maxGeometryCount: number,\n maxVertexCount: number,\n maxIndexCount = maxVertexCount * 2,\n material?: Material,\n ) {\n super(new BufferGeometry(), material)\n\n this._vertexStarts = []\n this._vertexCounts = []\n this._indexStarts = []\n this._indexCounts = []\n\n this._visibles = []\n this._alives = []\n\n this._maxGeometryCount = maxGeometryCount\n this._maxVertexCount = maxVertexCount\n this._maxIndexCount = maxIndexCount\n\n this._geometryInitialized = false\n this._geometryCount = 0\n this._vertexCount = 0\n this._indexCount = 0\n\n // Local matrix per geometry by using data texture\n // @TODO: Support uniform parameter per geometry\n\n this._matrices = []\n this._matricesArray = null\n this._matricesTexture = null\n this._matricesTextureSize = null\n\n // @TODO: Calculate the entire binding box and make frustumCulled true\n this.frustumCulled = false\n\n this._customUniforms = {\n batchingTexture: { value: null },\n batchingTextureSize: { value: 0 },\n }\n\n this._initMatricesTexture()\n this._initShader()\n\n this.onBeforeRender = function () {\n if (this.material.defines) {\n this.material.defines.BATCHING = true\n }\n\n // @TODO: Implement frustum culling for each geometry\n }\n\n this.onAfterRender = function () {\n if (this.material.defines) {\n this.material.defines.BATCHING = false\n }\n }\n }\n\n _initMatricesTexture() {\n // layout (1 matrix = 4 pixels)\n // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)\n // with 8x8 pixel texture max 16 matrices * 4 pixels = (8 * 8)\n // 16x16 pixel texture max 64 matrices * 4 pixels = (16 * 16)\n // 32x32 pixel texture max 256 matrices * 4 pixels = (32 * 32)\n // 64x64 pixel texture max 1024 matrices * 4 pixels = (64 * 64)\n\n let size = Math.sqrt(this._maxGeometryCount * 4) // 4 pixels needed for 1 matrix\n size = MathUtils.ceilPowerOfTwo(size)\n size = Math.max(size, 4)\n\n const matricesArray = new Float32Array(size * size * 4) // 4 floats per RGBA pixel\n const matricesTexture = new DataTexture(matricesArray, size, size, RGBAFormat, FloatType)\n\n this._matricesArray = matricesArray\n this._matricesTexture = matricesTexture\n this._matricesTextureSize = size\n\n this._customUniforms.batchingTexture.value = this._matricesTexture\n this._customUniforms.batchingTextureSize.value = this._matricesTextureSize\n }\n\n _initShader() {\n const currentOnBeforeCompile = this.material.onBeforeCompile\n const customUniforms = this._customUniforms\n\n this.material.onBeforeCompile = function onBeforeCompile(parameters, renderer) {\n // Is this replacement stable across any materials?\n parameters.vertexShader = parameters.vertexShader\n .replace('#include <skinning_pars_vertex>', '#include <skinning_pars_vertex>\\n' + batchingParsVertex)\n .replace(\n '#include <skinnormal_vertex>',\n '#include <skinnormal_vertex>\\n' + batchingbaseVertex + batchingnormalVertex,\n )\n .replace('#include <skinning_vertex>', '#include <skinning_vertex>\\n' + batchingVertex)\n\n for (const uniformName in customUniforms) {\n parameters.uniforms[uniformName] = customUniforms[uniformName]\n }\n\n currentOnBeforeCompile.call(this, parameters, renderer)\n }\n\n this.material.defines = this.material.defines || {}\n this.material.defines.BATCHING = false\n }\n\n getGeometryCount() {\n return this._geometryCount\n }\n\n getVertexCount() {\n return this._vertexCount\n }\n\n getIndexCount() {\n return this._indexCount\n }\n\n applyGeometry(geometry: BufferGeometry) {\n // @TODO: geometry.groups support?\n // @TODO: geometry.drawRange support?\n // @TODO: geometry.mortphAttributes support?\n\n if (this._geometryCount >= this._maxGeometryCount) {\n // @TODO: Error handling\n }\n\n if (this._geometryInitialized === false) {\n for (const attributeName in geometry.attributes) {\n const srcAttribute = geometry.getAttribute(attributeName)\n const { array, itemSize, normalized } = srcAttribute\n\n const dstArray = new (array.constructor as Float32ArrayConstructor)(this._maxVertexCount * itemSize)\n const dstAttribute = new (srcAttribute.constructor as any)(dstArray, itemSize, normalized) as BufferAttribute\n\n // TODO: add usage in @types/three\n // @ts-ignore\n dstAttribute.setUsage(srcAttribute.usage)\n\n this.geometry.setAttribute(attributeName, dstAttribute)\n }\n\n if (geometry.getIndex() !== null) {\n const indexArray =\n this._maxVertexCount > 65536 ? new Uint32Array(this._maxIndexCount) : new Uint16Array(this._maxIndexCount)\n\n this.geometry.setIndex(new BufferAttribute(indexArray, 1))\n }\n\n const idArray =\n this._maxGeometryCount > 65536 ? new Uint32Array(this._maxVertexCount) : new Uint16Array(this._maxVertexCount)\n // @TODO: What if attribute name 'id' is already used?\n this.geometry.setAttribute('id', new BufferAttribute(idArray, 1))\n\n this._geometryInitialized = true\n } else {\n // @TODO: Check if geometry has the same attributes set\n }\n\n const hasIndex = this.geometry.getIndex() !== null\n const dstIndex = this.geometry.getIndex()\n const srcIndex = geometry.getIndex()\n\n // Assuming geometry has position attribute\n const srcPositionAttribute = geometry.getAttribute('position')\n\n this._vertexStarts.push(this._vertexCount)\n this._vertexCounts.push(srcPositionAttribute.count)\n\n if (hasIndex) {\n this._indexStarts.push(this._indexCount)\n this._indexCounts.push(srcIndex!.count)\n }\n\n this._visibles.push(true)\n this._alives.push(true)\n\n // @TODO: Error handling if exceeding maxVertexCount or maxIndexCount\n\n for (const attributeName in geometry.attributes) {\n const srcAttribute = geometry.getAttribute(attributeName)\n const dstAttribute = this.geometry.getAttribute(attributeName)\n ;(dstAttribute.array as Float32Array).set(srcAttribute.array, this._vertexCount * dstAttribute.itemSize)\n dstAttribute.needsUpdate = true\n }\n\n if (hasIndex) {\n for (let i = 0; i < srcIndex!.count; i++) {\n dstIndex!.setX(this._indexCount + i, this._vertexCount + srcIndex!.getX(i))\n }\n\n this._indexCount += srcIndex!.count\n dstIndex!.needsUpdate = true\n }\n\n const geometryId = this._geometryCount\n this._geometryCount++\n\n const idAttribute = this.geometry.getAttribute('id')\n\n for (let i = 0; i < srcPositionAttribute.count; i++) {\n idAttribute.setX(this._vertexCount + i, geometryId)\n }\n\n idAttribute.needsUpdate = true\n\n this._vertexCount += srcPositionAttribute.count\n\n this._matrices.push(new Matrix4())\n _identityMatrix.toArray(this._matricesArray ?? undefined, geometryId * 16)\n this._matricesTexture!.needsUpdate = true\n\n return geometryId\n }\n\n deleteGeometry(geometryId: number) {\n if (geometryId >= this._alives.length || this._alives[geometryId] === false) {\n return this\n }\n\n this._alives[geometryId] = false\n _zeroScaleMatrix.toArray(this._matricesArray!, geometryId * 16)\n this._matricesTexture!.needsUpdate = true\n\n // User needs to call optimize() to pack the data.\n\n return this\n }\n\n optimize() {\n // @TODO: Implement\n\n return this\n }\n\n setMatrixAt(geometryId: number, matrix: Matrix4) {\n // @TODO: Map geometryId to index of the arrays because\n // optimize() can make geometryId mismatch the index\n\n if (geometryId >= this._matrices.length || this._alives[geometryId] === false) {\n return this\n }\n\n this._matrices[geometryId].copy(matrix)\n\n if (this._visibles[geometryId] === true) {\n matrix.toArray(this._matricesArray!, geometryId * 16)\n this._matricesTexture!.needsUpdate = true\n }\n\n return this\n }\n\n getMatrixAt(geometryId: number, matrix: Matrix4) {\n if (geometryId >= this._matrices.length || this._alives[geometryId] === false) {\n return matrix\n }\n\n return matrix.copy(this._matrices[geometryId])\n }\n\n setVisibleAt(geometryId: number, visible: boolean) {\n if (geometryId >= this._visibles.length || this._alives[geometryId] === false) {\n return this\n }\n\n if (this._visibles[geometryId] === visible) {\n return this\n }\n\n if (visible === true) {\n this._matrices[geometryId].toArray(this._matricesArray!, geometryId * 16)\n } else {\n _zeroScaleMatrix.toArray(this._matricesArray!, geometryId * 16)\n }\n\n this._matricesTexture!.needsUpdate = true\n this._visibles[geometryId] = visible\n return this\n }\n\n getVisibleAt(geometryId: number) {\n if (geometryId >= this._visibles.length || this._alives[geometryId] === false) {\n return false\n }\n\n return this._visibles[geometryId]\n }\n\n copy(source: BatchedMesh) {\n // @ts-ignore\n super.copy(source)\n\n // @TODO: Implement\n\n return this\n }\n\n toJSON(meta: any) {\n // @TODO: Implement\n\n return super.toJSON(meta)\n }\n\n dispose() {\n // Assuming the geometry is not shared with other meshes\n this.geometry.dispose()\n\n this._matricesTexture?.dispose()\n this._matricesTexture = null\n\n return this\n }\n}\n\nexport { BatchedMesh }\n"],"names":["Matrix4","Mesh","BufferGeometry","MathUtils","DataTexture","RGBAFormat","FloatType","BufferAttribute"],"mappings":";;;;;;;;;AAaA,MAAM,kBAAkB,IAAIA,MAAAA;AAC5B,MAAM,mBAAmB,IAAIA,cAAQ,EAAE,IAAI,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC;AAGzF,MAAM;AAAA;AAAA,EAAgC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAqBtC,MAAM;AAAA;AAAA,EAAgC;AAAA;AAAA;AAAA;AAAA;AAAA;AAMtC,MAAM;AAAA;AAAA,EAAkC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AASxC,MAAM;AAAA;AAAA,EAA4B;AAAA;AAAA;AAAA;AAAA;AAAA;AASlC,MAAM,oBAAoBC,MAAAA,KAA+B;AAAA,EAoBvD,YACE,kBACA,gBACA,gBAAgB,iBAAiB,GACjC,UACA;AACM,UAAA,IAAIC,MAAAA,kBAAkB,QAAQ;AAzBtC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;A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B,aAAa,EAAE;AAAA,IAAA,OACnE;AACL,uBAAiB,QAAQ,KAAK,gBAAiB,aAAa,EAAE;AAAA,IAChE;AAEA,SAAK,iBAAkB,cAAc;AAChC,SAAA,UAAU,UAAU,IAAI;AACtB,WAAA;AAAA,EACT;AAAA,EAEA,aAAa,YAAoB;AAC3B,QAAA,cAAc,KAAK,UAAU,UAAU,KAAK,QAAQ,UAAU,MAAM,OAAO;AACtE,aAAA;AAAA,IACT;AAEO,WAAA,KAAK,UAAU,UAAU;AAAA,EAClC;AAAA,EAEA,KAAK,QAAqB;AAExB,UAAM,KAAK,MAAM;AAIV,WAAA;AAAA,EACT;AAAA,EAEA,OAAO,MAAW;AAGT,WAAA,MAAM,OAAO,IAAI;AAAA,EAC1B;AAAA,EAEA,UAAU;;AAER,SAAK,SAAS;AAEd,eAAK,qBAAL,mBAAuB;AACvB,SAAK,mBAAmB;AAEjB,WAAA;AAAA,EACT;AACF;;"}
|
1
|
+
{"version":3,"file":"BatchedMesh.cjs","sources":["../../src/objects/BatchedMesh.ts"],"sourcesContent":["import {\n Matrix4,\n BufferAttribute,\n InterleavedBufferAttribute,\n Mesh,\n BufferGeometry,\n Material,\n DataTexture,\n IUniform,\n MathUtils,\n RGBAFormat,\n FloatType,\n} from 'three'\n\nconst ID_ATTR_NAME = '_batch_id_'\nconst _identityMatrix = new Matrix4()\nconst _zeroScaleMatrix = new Matrix4().set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1)\n\n// Custom shaders\nconst batchingParsVertex = /* glsl */ `\n#ifdef BATCHING\n\tattribute float ${ID_ATTR_NAME};\n\tuniform highp sampler2D batchingTexture;\n\tmat4 getBatchingMatrix( const in float i ) {\n\n\t\tint size = textureSize( batchingTexture, 0 ).x;\n\t\tint j = int( i ) * 4;\n\t\tint x = j % size;\n\t\tint y = j / size;\n\t\tvec4 v1 = texelFetch( batchingTexture, ivec2( x, y ), 0 );\n\t\tvec4 v2 = texelFetch( batchingTexture, ivec2( x + 1, y ), 0 );\n\t\tvec4 v3 = texelFetch( batchingTexture, ivec2( x + 2, y ), 0 );\n\t\tvec4 v4 = texelFetch( batchingTexture, ivec2( x + 3, y ), 0 );\n\t\treturn mat4( v1, v2, v3, v4 );\n\n\t}\n#endif\n`\n\nconst batchingbaseVertex = /* glsl */ `\n#ifdef BATCHING\n\tmat4 batchingMatrix = getBatchingMatrix( ${ID_ATTR_NAME} );\n#endif\n`\n\nconst batchingnormalVertex = /* glsl */ `\n#ifdef BATCHING\n\tobjectNormal = vec4( batchingMatrix * vec4( objectNormal, 0.0 ) ).xyz;\n\t#ifdef USE_TANGENT\n\t\tobjectTangent = vec4( batchingMatrix * vec4( objectTangent, 0.0 ) ).xyz;\n\t#endif\n#endif\n`\n\nconst batchingVertex = /* glsl */ `\n#ifdef BATCHING\n\ttransformed = ( batchingMatrix * vec4( transformed, 1.0 ) ).xyz;\n#endif\n`\n\n// @TODO: SkinnedMesh support?\n// @TODO: Future work if needed. Move into the core. Can be optimized more with WEBGL_multi_draw.\n\n// copies data from attribute \"src\" into \"target\" starting at \"targetOffset\"\nfunction copyAttributeData(\n src: BufferAttribute | InterleavedBufferAttribute,\n target: BufferAttribute | InterleavedBufferAttribute,\n targetOffset = 0,\n): void {\n const itemSize = target.itemSize\n if (\n (src as InterleavedBufferAttribute).isInterleavedBufferAttribute ||\n src.array.constructor !== target.array.constructor\n ) {\n // use the component getters and setters if the array data cannot\n // be copied directly\n const vertexCount = src.count\n for (let i = 0; i < vertexCount; i++) {\n for (let c = 0; c < itemSize; c++) {\n // @ts-ignore\n target.setComponent(i + targetOffset, c, src.getComponent(i, c))\n }\n }\n } else {\n // faster copy approach using typed array set function\n // @ts-ignore\n target.array.set(src.array, targetOffset * itemSize)\n }\n\n target.needsUpdate = true\n}\n\nclass BatchedMesh extends Mesh<BufferGeometry, Material> {\n _vertexStarts: number[]\n _vertexCounts: number[]\n _indexStarts: number[]\n _indexCounts: number[]\n _reservedRanges: { vertexStart: number; vertexCount: number; indexStart: number; indexCount: number }[]\n _visible: boolean[]\n _active: boolean[]\n _maxGeometryCount: number\n _maxVertexCount: number\n _maxIndexCount: number\n _geometryInitialized: boolean\n _geometryCount: number\n _matrices: Matrix4[]\n _matricesTexture: DataTexture | null\n _customUniforms: Record<string, IUniform>\n\n constructor(\n maxGeometryCount: number,\n maxVertexCount: number,\n maxIndexCount = maxVertexCount * 2,\n material?: Material,\n ) {\n super(new BufferGeometry(), material)\n\n this._vertexStarts = []\n this._vertexCounts = []\n this._indexStarts = []\n this._indexCounts = []\n this._reservedRanges = []\n\n this._visible = []\n this._active = []\n\n this._maxGeometryCount = maxGeometryCount\n this._maxVertexCount = maxVertexCount\n this._maxIndexCount = maxIndexCount\n\n this._geometryInitialized = false\n this._geometryCount = 0\n\n // Local matrix per geometry by using data texture\n // @TODO: Support uniform parameter per geometry\n\n this._matrices = []\n this._matricesTexture = null!\n\n // @TODO: Calculate the entire binding box and make frustumCulled true\n this.frustumCulled = false\n\n this._customUniforms = {\n batchingTexture: { value: null },\n }\n\n this._initMatricesTexture()\n this._initShader()\n\n this.onBeforeRender = function () {\n if (this.material.defines) {\n this.material.defines.BATCHING = true\n }\n\n // @TODO: Implement frustum culling for each geometry\n }\n\n this.onAfterRender = function () {\n if (this.material.defines) {\n this.material.defines.BATCHING = false\n }\n }\n }\n\n _initMatricesTexture(): void {\n // layout (1 matrix = 4 pixels)\n // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)\n // with 8x8 pixel texture max 16 matrices * 4 pixels = (8 * 8)\n // 16x16 pixel texture max 64 matrices * 4 pixels = (16 * 16)\n // 32x32 pixel texture max 256 matrices * 4 pixels = (32 * 32)\n // 64x64 pixel texture max 1024 matrices * 4 pixels = (64 * 64)\n\n let size = Math.sqrt(this._maxGeometryCount * 4) // 4 pixels needed for 1 matrix\n size = MathUtils.ceilPowerOfTwo(size)\n size = Math.max(size, 4)\n\n const matricesArray = new Float32Array(size * size * 4) // 4 floats per RGBA pixel\n const matricesTexture = new DataTexture(matricesArray, size, size, RGBAFormat, FloatType)\n\n this._matricesTexture = matricesTexture\n this._customUniforms.batchingTexture.value = this._matricesTexture\n }\n\n _initShader(): void {\n const material = this.material\n const currentOnBeforeCompile = material.onBeforeCompile\n const customUniforms = this._customUniforms\n\n material.onBeforeCompile = function onBeforeCompile(parameters, renderer) {\n // Is this replacement stable across any materials?\n parameters.vertexShader = parameters.vertexShader\n .replace('#include <skinning_pars_vertex>', '#include <skinning_pars_vertex>\\n' + batchingParsVertex)\n .replace('#include <uv_vertex>', '#include <uv_vertex>\\n' + batchingbaseVertex)\n .replace('#include <skinnormal_vertex>', '#include <skinnormal_vertex>\\n' + batchingnormalVertex)\n .replace('#include <skinning_vertex>', '#include <skinning_vertex>\\n' + batchingVertex)\n\n for (const uniformName in customUniforms) {\n parameters.uniforms[uniformName] = customUniforms[uniformName]\n }\n\n currentOnBeforeCompile.call(this, parameters, renderer)\n }\n\n material.defines = material.defines || {}\n material.defines.BATCHING = false\n }\n\n _initializeGeometry(reference: BufferGeometry): void {\n // @TODO: geometry.groups support?\n // @TODO: geometry.drawRange support?\n // @TODO: geometry.morphAttributes support?\n\n const geometry = this.geometry\n const maxVertexCount = this._maxVertexCount\n const maxGeometryCount = this._maxGeometryCount\n const maxIndexCount = this._maxIndexCount\n if (this._geometryInitialized === false) {\n for (const attributeName in reference.attributes) {\n const srcAttribute = reference.getAttribute(attributeName)\n const { array, itemSize, normalized } = srcAttribute\n\n const dstArray = new (array.constructor as Float32ArrayConstructor)(maxVertexCount * itemSize)\n const dstAttribute = new (srcAttribute.constructor as any)(dstArray, itemSize, normalized)\n\n // TODO: add usage in @types/three\n // @ts-ignore\n dstAttribute.setUsage(srcAttribute.usage)\n\n geometry.setAttribute(attributeName, dstAttribute)\n }\n\n if (reference.getIndex() !== null) {\n const indexArray = maxVertexCount > 65536 ? new Uint32Array(maxIndexCount) : new Uint16Array(maxIndexCount)\n\n geometry.setIndex(new BufferAttribute(indexArray, 1))\n }\n\n const idArray = maxGeometryCount > 65536 ? new Uint32Array(maxVertexCount) : new Uint16Array(maxVertexCount)\n geometry.setAttribute(ID_ATTR_NAME, new BufferAttribute(idArray, 1))\n\n this._geometryInitialized = true\n }\n }\n\n // Make sure the geometry is compatible with the existing combined geometry atributes\n _validateGeometry(geometry: BufferGeometry): void {\n // check that the geometry doesn't have a version of our reserved id attribute\n if (geometry.getAttribute(ID_ATTR_NAME)) {\n throw new Error(`BatchedMesh: Geometry cannot use attribute \"${ID_ATTR_NAME}\"`)\n }\n\n // check to ensure the geometries are using consistent attributes and indices\n const batchGeometry = this.geometry\n if (Boolean(geometry.getIndex()) !== Boolean(batchGeometry.getIndex())) {\n throw new Error('BatchedMesh: All geometries must consistently have \"index\".')\n }\n\n for (const attributeName in batchGeometry.attributes) {\n if (attributeName === ID_ATTR_NAME) {\n continue\n }\n\n if (!geometry.hasAttribute(attributeName)) {\n throw new Error(\n `BatchedMesh: Added geometry missing \"${attributeName}\". All geometries must have consistent attributes.`,\n )\n }\n\n const srcAttribute = geometry.getAttribute(attributeName)\n const dstAttribute = batchGeometry.getAttribute(attributeName)\n if (srcAttribute.itemSize !== dstAttribute.itemSize || srcAttribute.normalized !== dstAttribute.normalized) {\n throw new Error('BatchedMesh: All attributes must have a consistent itemSize and normalized value.')\n }\n }\n }\n\n getGeometryCount(): number {\n return this._geometryCount\n }\n\n getVertexCount(): number {\n const reservedRanges = this._reservedRanges\n if (reservedRanges.length === 0) {\n return 0\n } else {\n const finalRange = reservedRanges[reservedRanges.length - 1]\n return finalRange.vertexStart + finalRange.vertexCount\n }\n }\n\n getIndexCount(): number {\n const reservedRanges = this._reservedRanges\n const geometry = this.geometry\n if (geometry.getIndex() === null || reservedRanges.length === 0) {\n return 0\n } else {\n const finalRange = reservedRanges[reservedRanges.length - 1]\n return finalRange.indexStart + finalRange.indexCount\n }\n }\n\n addGeometry(geometry: BufferGeometry, vertexCount = -1, indexCount = -1): number {\n this._initializeGeometry(geometry)\n\n this._validateGeometry(geometry)\n\n // ensure we're not over geometry\n if (this._geometryCount >= this._maxGeometryCount) {\n throw new Error('BatchedMesh: Maximum geometry count reached.')\n }\n\n // get the necessary range fo the geometry\n const range = {\n vertexStart: -1,\n vertexCount: -1,\n indexStart: -1,\n indexCount: -1,\n }\n\n let lastRange = null\n const reservedRanges = this._reservedRanges\n if (this._geometryCount !== 0) {\n lastRange = reservedRanges[reservedRanges.length - 1]\n }\n\n if (vertexCount === -1) {\n range.vertexCount = geometry.getAttribute('position').count\n } else {\n range.vertexCount = vertexCount\n }\n\n if (lastRange === null) {\n range.vertexStart = 0\n } else {\n range.vertexStart = lastRange.vertexStart + lastRange.vertexCount\n }\n\n if (geometry.getIndex() !== null) {\n if (indexCount === -1) {\n range.indexCount = geometry.getIndex()!.count\n } else {\n range.indexCount = indexCount\n }\n\n if (lastRange === null) {\n range.indexStart = 0\n } else {\n range.indexStart = lastRange.indexStart + lastRange.indexCount\n }\n }\n\n if (\n (range.indexStart !== -1 && range.indexStart + range.indexCount > this._maxIndexCount) ||\n range.vertexStart + range.vertexCount > this._maxVertexCount\n ) {\n throw new Error('BatchedMesh: Reserved space request exceeds the maximum buffer size.')\n }\n\n const indexCounts = this._indexCounts\n const indexStarts = this._indexStarts\n const vertexCounts = this._vertexCounts\n const vertexStarts = this._vertexStarts\n\n const visible = this._visible\n const active = this._active\n const matricesTexture = this._matricesTexture\n const matrices = this._matrices\n const matricesArray = this._matricesTexture!.image.data\n\n // push new visibility states\n visible.push(true)\n active.push(true)\n\n // update id\n const geometryId = this._geometryCount\n this._geometryCount++\n\n // initialize matrix information\n matrices.push(new Matrix4())\n _identityMatrix.toArray(matricesArray, geometryId * 16)\n matricesTexture!.needsUpdate = true\n\n // add the reserved range\n reservedRanges.push(range)\n\n // push new geometry data range\n vertexStarts.push(range.vertexStart)\n vertexCounts.push(range.vertexCount)\n\n if (geometry.getIndex() !== null) {\n // push new index range\n indexStarts.push(range.indexCount)\n indexCounts.push(range.indexCount)\n }\n\n // set the id for the geometry\n const idAttribute = this.geometry.getAttribute(ID_ATTR_NAME)\n for (let i = 0; i < range.vertexCount; i++) {\n idAttribute.setX(range.vertexStart + i, geometryId)\n }\n\n idAttribute.needsUpdate = true\n\n // update the geometry\n this.setGeometryAt(geometryId, geometry)\n\n return geometryId\n }\n\n /**\n * @deprecated use `addGeometry` instead.\n */\n applyGeometry(geometry: BufferGeometry): number {\n return this.addGeometry(geometry)\n }\n\n setGeometryAt(id: number, geometry: BufferGeometry): number {\n if (id >= this._geometryCount) {\n throw new Error('BatchedMesh: Maximum geometry count reached.')\n }\n\n this._validateGeometry(geometry)\n\n const range = this._reservedRanges[id]\n if (\n (geometry.getIndex() !== null && geometry.getIndex()!.count > range.indexCount) ||\n geometry.attributes.position.count > range.vertexCount\n ) {\n throw new Error('BatchedMesh: Reserved space not large enough for provided geometry.')\n }\n\n // copy geometry over\n const batchGeometry = this.geometry\n const srcPositionAttribute = geometry.getAttribute('position')\n const hasIndex = batchGeometry.getIndex() !== null\n const dstIndex = batchGeometry.getIndex()!\n const srcIndex = geometry.getIndex()!\n\n // copy attribute data over\n const vertexStart = range.vertexStart\n const vertexCount = range.vertexCount\n for (const attributeName in batchGeometry.attributes) {\n if (attributeName === ID_ATTR_NAME) {\n continue\n }\n\n const srcAttribute = geometry.getAttribute(attributeName)\n const dstAttribute = batchGeometry.getAttribute(attributeName)\n copyAttributeData(srcAttribute, dstAttribute, vertexStart)\n\n // fill the rest in with zeroes\n const itemSize = srcAttribute.itemSize\n for (let i = srcAttribute.count, l = vertexCount; i < l; i++) {\n const index = vertexStart + i\n for (let c = 0; c < itemSize; c++) {\n // @ts-ignore\n dstAttribute.setComponent(index, c, 0)\n }\n }\n\n dstAttribute.needsUpdate = true\n }\n\n this._vertexCounts[id] = srcPositionAttribute.count\n\n if (hasIndex) {\n // fill the rest in with zeroes\n const indexStart = range.indexStart\n\n // copy index data over\n for (let i = 0; i < srcIndex.count; i++) {\n dstIndex.setX(indexStart + i, vertexStart + srcIndex.getX(i))\n }\n\n // fill the rest in with zeroes\n for (let i = srcIndex.count, l = range.indexCount; i < l; i++) {\n dstIndex.setX(indexStart + i, vertexStart)\n }\n\n dstIndex.needsUpdate = true\n this._indexCounts[id] = srcIndex.count\n }\n\n return id\n }\n\n deleteGeometry(geometryId: number): this {\n // Note: User needs to call optimize() afterward to pack the data.\n\n const active = this._active\n const matricesTexture = this._matricesTexture!\n const matricesArray = matricesTexture.image.data\n if (geometryId >= active.length || active[geometryId] === false) {\n return this\n }\n\n active[geometryId] = false\n _zeroScaleMatrix.toArray(matricesArray, geometryId * 16)\n matricesTexture!.needsUpdate = true\n\n return this\n }\n\n optimize(): never {\n throw new Error('BatchedMesh: Optimize function not implemented.')\n }\n\n setMatrixAt(geometryId: number, matrix: Matrix4): this {\n // @TODO: Map geometryId to index of the arrays because\n // optimize() can make geometryId mismatch the index\n\n const visible = this._visible\n const active = this._active\n const matricesTexture = this._matricesTexture!\n const matrices = this._matrices\n const matricesArray = matricesTexture.image.data\n if (geometryId >= matrices.length || active[geometryId] === false) {\n return this\n }\n\n if (visible[geometryId] === true) {\n matrix.toArray(matricesArray, geometryId * 16)\n matricesTexture.needsUpdate = true\n }\n\n matrices[geometryId].copy(matrix)\n\n return this\n }\n\n getMatrixAt(geometryId: number, matrix: Matrix4): Matrix4 {\n const matrices = this._matrices\n const active = this._active\n if (geometryId >= matrices.length || active[geometryId] === false) {\n return matrix\n }\n\n return matrix.copy(matrices[geometryId])\n }\n\n setVisibleAt(geometryId: number, value: boolean): this {\n const visible = this._visible\n const active = this._active\n const matricesTexture = this._matricesTexture!\n const matrices = this._matrices\n const matricesArray = matricesTexture.image.data\n\n // if the geometry is out of range, not active, or visibility state\n // does not change then return early\n if (geometryId >= visible.length || active[geometryId] === false || visible[geometryId] === value) {\n return this\n }\n\n // scale the matrix to zero if it's hidden\n if (value === true) {\n matrices[geometryId].toArray(matricesArray, geometryId * 16)\n } else {\n _zeroScaleMatrix.toArray(matricesArray, geometryId * 16)\n }\n\n matricesTexture.needsUpdate = true\n visible[geometryId] = value\n\n return this\n }\n\n getVisibleAt(geometryId: number): boolean {\n const visible = this._visible\n const active = this._active\n\n // return early if the geometry is out of range or not active\n if (geometryId >= visible.length || active[geometryId] === false) {\n return false\n }\n\n return visible[geometryId]\n }\n\n raycast(): void {\n console.warn('BatchedMesh: Raycast function not implemented.')\n }\n\n copy(): never {\n // super.copy( source );\n\n throw new Error('BatchedMesh: Copy function not implemented.')\n }\n\n toJSON(): never {\n throw new Error('BatchedMesh: toJSON function not implemented.')\n }\n\n dispose(): this {\n // Assuming the geometry is not shared with other meshes\n this.geometry.dispose()\n\n this._matricesTexture!.dispose()\n this._matricesTexture = null!\n\n return this\n }\n}\n\nexport { BatchedMesh }\n"],"names":["Matrix4","Mesh","BufferGeometry","MathUtils","DataTexture","RGBAFormat","FloatType","BufferAttribute"],"mappings":";;;;;;;;;AAcA,MAAM,eAAe;AACrB,MAAM,kBAAkB,IAAIA,MAAAA;AAC5B,MAAM,mBAAmB,IAAIA,cAAQ,EAAE,IAAI,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC;AAGzF,MAAM;AAAA;AAAA,EAAgC;AAAA;AAAA,mBAEnB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAkBnB,MAAM;AAAA;AAAA,EAAgC;AAAA;AAAA,4CAEM;AAAA;AAAA;AAAA;AAI5C,MAAM;AAAA;AAAA,EAAkC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AASxC,MAAM;AAAA;AAAA,EAA4B;AAAA;AAAA;AAAA;AAAA;AAAA;AAUlC,SAAS,kBACP,KACA,QACA,eAAe,GACT;AACN,QAAM,WAAW,OAAO;AACxB,MACG,IAAmC,gCACpC,IAAI,MAAM,gBAAgB,O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