three-stdlib 2.28.3 → 2.28.5
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/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.d.ts
CHANGED
@@ -4,35 +4,45 @@ declare class BatchedMesh extends Mesh<BufferGeometry, Material> {
|
|
4
4
|
_vertexCounts: number[];
|
5
5
|
_indexStarts: number[];
|
6
6
|
_indexCounts: number[];
|
7
|
-
|
8
|
-
|
7
|
+
_reservedRanges: {
|
8
|
+
vertexStart: number;
|
9
|
+
vertexCount: number;
|
10
|
+
indexStart: number;
|
11
|
+
indexCount: number;
|
12
|
+
}[];
|
13
|
+
_visible: boolean[];
|
14
|
+
_active: boolean[];
|
9
15
|
_maxGeometryCount: number;
|
10
16
|
_maxVertexCount: number;
|
11
17
|
_maxIndexCount: number;
|
12
18
|
_geometryInitialized: boolean;
|
13
19
|
_geometryCount: number;
|
14
|
-
_vertexCount: number;
|
15
|
-
_indexCount: number;
|
16
20
|
_matrices: Matrix4[];
|
17
|
-
_matricesArray: Float32Array | null;
|
18
21
|
_matricesTexture: DataTexture | null;
|
19
|
-
_matricesTextureSize: number | null;
|
20
22
|
_customUniforms: Record<string, IUniform>;
|
21
23
|
constructor(maxGeometryCount: number, maxVertexCount: number, maxIndexCount?: number, material?: Material);
|
22
24
|
_initMatricesTexture(): void;
|
23
25
|
_initShader(): void;
|
26
|
+
_initializeGeometry(reference: BufferGeometry): void;
|
27
|
+
_validateGeometry(geometry: BufferGeometry): void;
|
24
28
|
getGeometryCount(): number;
|
25
29
|
getVertexCount(): number;
|
26
30
|
getIndexCount(): number;
|
31
|
+
addGeometry(geometry: BufferGeometry, vertexCount?: number, indexCount?: number): number;
|
32
|
+
/**
|
33
|
+
* @deprecated use `addGeometry` instead.
|
34
|
+
*/
|
27
35
|
applyGeometry(geometry: BufferGeometry): number;
|
36
|
+
setGeometryAt(id: number, geometry: BufferGeometry): number;
|
28
37
|
deleteGeometry(geometryId: number): this;
|
29
|
-
optimize():
|
38
|
+
optimize(): never;
|
30
39
|
setMatrixAt(geometryId: number, matrix: Matrix4): this;
|
31
40
|
getMatrixAt(geometryId: number, matrix: Matrix4): Matrix4;
|
32
|
-
setVisibleAt(geometryId: number,
|
41
|
+
setVisibleAt(geometryId: number, value: boolean): this;
|
33
42
|
getVisibleAt(geometryId: number): boolean;
|
34
|
-
|
35
|
-
|
43
|
+
raycast(): void;
|
44
|
+
copy(): never;
|
45
|
+
toJSON(): never;
|
36
46
|
dispose(): this;
|
37
47
|
}
|
38
48
|
export { BatchedMesh };
|
package/objects/BatchedMesh.js
CHANGED
@@ -5,27 +5,27 @@ var __publicField = (obj, key, value) => {
|
|
5
5
|
return value;
|
6
6
|
};
|
7
7
|
import { Matrix4, Mesh, BufferGeometry, MathUtils, DataTexture, RGBAFormat, FloatType, BufferAttribute } from "three";
|
8
|
+
const ID_ATTR_NAME = "_batch_id_";
|
8
9
|
const _identityMatrix = new Matrix4();
|
9
10
|
const _zeroScaleMatrix = new Matrix4().set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1);
|
10
11
|
const batchingParsVertex = (
|
11
12
|
/* glsl */
|
12
13
|
`
|
13
14
|
#ifdef BATCHING
|
14
|
-
attribute float
|
15
|
+
attribute float ${ID_ATTR_NAME};
|
15
16
|
uniform highp sampler2D batchingTexture;
|
16
|
-
uniform int batchingTextureSize;
|
17
17
|
mat4 getBatchingMatrix( const in float i ) {
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
vec4
|
25
|
-
vec4
|
26
|
-
vec4
|
27
|
-
vec4 v4 = texture2D( batchingTexture, vec2( dx * ( x + 3.5 ), y ) );
|
18
|
+
|
19
|
+
int size = textureSize( batchingTexture, 0 ).x;
|
20
|
+
int j = int( i ) * 4;
|
21
|
+
int x = j % size;
|
22
|
+
int y = j / size;
|
23
|
+
vec4 v1 = texelFetch( batchingTexture, ivec2( x, y ), 0 );
|
24
|
+
vec4 v2 = texelFetch( batchingTexture, ivec2( x + 1, y ), 0 );
|
25
|
+
vec4 v3 = texelFetch( batchingTexture, ivec2( x + 2, y ), 0 );
|
26
|
+
vec4 v4 = texelFetch( batchingTexture, ivec2( x + 3, y ), 0 );
|
28
27
|
return mat4( v1, v2, v3, v4 );
|
28
|
+
|
29
29
|
}
|
30
30
|
#endif
|
31
31
|
`
|
@@ -34,7 +34,7 @@ const batchingbaseVertex = (
|
|
34
34
|
/* glsl */
|
35
35
|
`
|
36
36
|
#ifdef BATCHING
|
37
|
-
mat4 batchingMatrix = getBatchingMatrix(
|
37
|
+
mat4 batchingMatrix = getBatchingMatrix( ${ID_ATTR_NAME} );
|
38
38
|
#endif
|
39
39
|
`
|
40
40
|
);
|
@@ -57,6 +57,20 @@ const batchingVertex = (
|
|
57
57
|
#endif
|
58
58
|
`
|
59
59
|
);
|
60
|
+
function copyAttributeData(src, target, targetOffset = 0) {
|
61
|
+
const itemSize = target.itemSize;
|
62
|
+
if (src.isInterleavedBufferAttribute || src.array.constructor !== target.array.constructor) {
|
63
|
+
const vertexCount = src.count;
|
64
|
+
for (let i = 0; i < vertexCount; i++) {
|
65
|
+
for (let c = 0; c < itemSize; c++) {
|
66
|
+
target.setComponent(i + targetOffset, c, src.getComponent(i, c));
|
67
|
+
}
|
68
|
+
}
|
69
|
+
} else {
|
70
|
+
target.array.set(src.array, targetOffset * itemSize);
|
71
|
+
}
|
72
|
+
target.needsUpdate = true;
|
73
|
+
}
|
60
74
|
class BatchedMesh extends Mesh {
|
61
75
|
constructor(maxGeometryCount, maxVertexCount, maxIndexCount = maxVertexCount * 2, material) {
|
62
76
|
super(new BufferGeometry(), material);
|
@@ -64,41 +78,34 @@ class BatchedMesh extends Mesh {
|
|
64
78
|
__publicField(this, "_vertexCounts");
|
65
79
|
__publicField(this, "_indexStarts");
|
66
80
|
__publicField(this, "_indexCounts");
|
67
|
-
__publicField(this, "
|
68
|
-
__publicField(this, "
|
81
|
+
__publicField(this, "_reservedRanges");
|
82
|
+
__publicField(this, "_visible");
|
83
|
+
__publicField(this, "_active");
|
69
84
|
__publicField(this, "_maxGeometryCount");
|
70
85
|
__publicField(this, "_maxVertexCount");
|
71
86
|
__publicField(this, "_maxIndexCount");
|
72
87
|
__publicField(this, "_geometryInitialized");
|
73
88
|
__publicField(this, "_geometryCount");
|
74
|
-
__publicField(this, "_vertexCount");
|
75
|
-
__publicField(this, "_indexCount");
|
76
89
|
__publicField(this, "_matrices");
|
77
|
-
__publicField(this, "_matricesArray");
|
78
90
|
__publicField(this, "_matricesTexture");
|
79
|
-
__publicField(this, "_matricesTextureSize");
|
80
91
|
__publicField(this, "_customUniforms");
|
81
92
|
this._vertexStarts = [];
|
82
93
|
this._vertexCounts = [];
|
83
94
|
this._indexStarts = [];
|
84
95
|
this._indexCounts = [];
|
85
|
-
this.
|
86
|
-
this.
|
96
|
+
this._reservedRanges = [];
|
97
|
+
this._visible = [];
|
98
|
+
this._active = [];
|
87
99
|
this._maxGeometryCount = maxGeometryCount;
|
88
100
|
this._maxVertexCount = maxVertexCount;
|
89
101
|
this._maxIndexCount = maxIndexCount;
|
90
102
|
this._geometryInitialized = false;
|
91
103
|
this._geometryCount = 0;
|
92
|
-
this._vertexCount = 0;
|
93
|
-
this._indexCount = 0;
|
94
104
|
this._matrices = [];
|
95
|
-
this._matricesArray = null;
|
96
105
|
this._matricesTexture = null;
|
97
|
-
this._matricesTextureSize = null;
|
98
106
|
this.frustumCulled = false;
|
99
107
|
this._customUniforms = {
|
100
|
-
batchingTexture: { value: null }
|
101
|
-
batchingTextureSize: { value: 0 }
|
108
|
+
batchingTexture: { value: null }
|
102
109
|
};
|
103
110
|
this._initMatricesTexture();
|
104
111
|
this._initShader();
|
@@ -119,158 +126,295 @@ class BatchedMesh extends Mesh {
|
|
119
126
|
size = Math.max(size, 4);
|
120
127
|
const matricesArray = new Float32Array(size * size * 4);
|
121
128
|
const matricesTexture = new DataTexture(matricesArray, size, size, RGBAFormat, FloatType);
|
122
|
-
this._matricesArray = matricesArray;
|
123
129
|
this._matricesTexture = matricesTexture;
|
124
|
-
this._matricesTextureSize = size;
|
125
130
|
this._customUniforms.batchingTexture.value = this._matricesTexture;
|
126
|
-
this._customUniforms.batchingTextureSize.value = this._matricesTextureSize;
|
127
131
|
}
|
128
132
|
_initShader() {
|
129
|
-
const
|
133
|
+
const material = this.material;
|
134
|
+
const currentOnBeforeCompile = material.onBeforeCompile;
|
130
135
|
const customUniforms = this._customUniforms;
|
131
|
-
|
132
|
-
parameters.vertexShader = parameters.vertexShader.replace("#include <skinning_pars_vertex>", "#include <skinning_pars_vertex>\n" + batchingParsVertex).replace(
|
133
|
-
"#include <skinnormal_vertex>",
|
134
|
-
"#include <skinnormal_vertex>\n" + batchingbaseVertex + batchingnormalVertex
|
135
|
-
).replace("#include <skinning_vertex>", "#include <skinning_vertex>\n" + batchingVertex);
|
136
|
+
material.onBeforeCompile = function onBeforeCompile(parameters, renderer) {
|
137
|
+
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);
|
136
138
|
for (const uniformName in customUniforms) {
|
137
139
|
parameters.uniforms[uniformName] = customUniforms[uniformName];
|
138
140
|
}
|
139
141
|
currentOnBeforeCompile.call(this, parameters, renderer);
|
140
142
|
};
|
141
|
-
|
142
|
-
|
143
|
+
material.defines = material.defines || {};
|
144
|
+
material.defines.BATCHING = false;
|
145
|
+
}
|
146
|
+
_initializeGeometry(reference) {
|
147
|
+
const geometry = this.geometry;
|
148
|
+
const maxVertexCount = this._maxVertexCount;
|
149
|
+
const maxGeometryCount = this._maxGeometryCount;
|
150
|
+
const maxIndexCount = this._maxIndexCount;
|
151
|
+
if (this._geometryInitialized === false) {
|
152
|
+
for (const attributeName in reference.attributes) {
|
153
|
+
const srcAttribute = reference.getAttribute(attributeName);
|
154
|
+
const { array, itemSize, normalized } = srcAttribute;
|
155
|
+
const dstArray = new array.constructor(maxVertexCount * itemSize);
|
156
|
+
const dstAttribute = new srcAttribute.constructor(dstArray, itemSize, normalized);
|
157
|
+
dstAttribute.setUsage(srcAttribute.usage);
|
158
|
+
geometry.setAttribute(attributeName, dstAttribute);
|
159
|
+
}
|
160
|
+
if (reference.getIndex() !== null) {
|
161
|
+
const indexArray = maxVertexCount > 65536 ? new Uint32Array(maxIndexCount) : new Uint16Array(maxIndexCount);
|
162
|
+
geometry.setIndex(new BufferAttribute(indexArray, 1));
|
163
|
+
}
|
164
|
+
const idArray = maxGeometryCount > 65536 ? new Uint32Array(maxVertexCount) : new Uint16Array(maxVertexCount);
|
165
|
+
geometry.setAttribute(ID_ATTR_NAME, new BufferAttribute(idArray, 1));
|
166
|
+
this._geometryInitialized = true;
|
167
|
+
}
|
168
|
+
}
|
169
|
+
// Make sure the geometry is compatible with the existing combined geometry atributes
|
170
|
+
_validateGeometry(geometry) {
|
171
|
+
if (geometry.getAttribute(ID_ATTR_NAME)) {
|
172
|
+
throw new Error(`BatchedMesh: Geometry cannot use attribute "${ID_ATTR_NAME}"`);
|
173
|
+
}
|
174
|
+
const batchGeometry = this.geometry;
|
175
|
+
if (Boolean(geometry.getIndex()) !== Boolean(batchGeometry.getIndex())) {
|
176
|
+
throw new Error('BatchedMesh: All geometries must consistently have "index".');
|
177
|
+
}
|
178
|
+
for (const attributeName in batchGeometry.attributes) {
|
179
|
+
if (attributeName === ID_ATTR_NAME) {
|
180
|
+
continue;
|
181
|
+
}
|
182
|
+
if (!geometry.hasAttribute(attributeName)) {
|
183
|
+
throw new Error(
|
184
|
+
`BatchedMesh: Added geometry missing "${attributeName}". All geometries must have consistent attributes.`
|
185
|
+
);
|
186
|
+
}
|
187
|
+
const srcAttribute = geometry.getAttribute(attributeName);
|
188
|
+
const dstAttribute = batchGeometry.getAttribute(attributeName);
|
189
|
+
if (srcAttribute.itemSize !== dstAttribute.itemSize || srcAttribute.normalized !== dstAttribute.normalized) {
|
190
|
+
throw new Error("BatchedMesh: All attributes must have a consistent itemSize and normalized value.");
|
191
|
+
}
|
192
|
+
}
|
143
193
|
}
|
144
194
|
getGeometryCount() {
|
145
195
|
return this._geometryCount;
|
146
196
|
}
|
147
197
|
getVertexCount() {
|
148
|
-
|
198
|
+
const reservedRanges = this._reservedRanges;
|
199
|
+
if (reservedRanges.length === 0) {
|
200
|
+
return 0;
|
201
|
+
} else {
|
202
|
+
const finalRange = reservedRanges[reservedRanges.length - 1];
|
203
|
+
return finalRange.vertexStart + finalRange.vertexCount;
|
204
|
+
}
|
149
205
|
}
|
150
206
|
getIndexCount() {
|
151
|
-
|
207
|
+
const reservedRanges = this._reservedRanges;
|
208
|
+
const geometry = this.geometry;
|
209
|
+
if (geometry.getIndex() === null || reservedRanges.length === 0) {
|
210
|
+
return 0;
|
211
|
+
} else {
|
212
|
+
const finalRange = reservedRanges[reservedRanges.length - 1];
|
213
|
+
return finalRange.indexStart + finalRange.indexCount;
|
214
|
+
}
|
152
215
|
}
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
216
|
+
addGeometry(geometry, vertexCount = -1, indexCount = -1) {
|
217
|
+
this._initializeGeometry(geometry);
|
218
|
+
this._validateGeometry(geometry);
|
219
|
+
if (this._geometryCount >= this._maxGeometryCount) {
|
220
|
+
throw new Error("BatchedMesh: Maximum geometry count reached.");
|
221
|
+
}
|
222
|
+
const range = {
|
223
|
+
vertexStart: -1,
|
224
|
+
vertexCount: -1,
|
225
|
+
indexStart: -1,
|
226
|
+
indexCount: -1
|
227
|
+
};
|
228
|
+
let lastRange = null;
|
229
|
+
const reservedRanges = this._reservedRanges;
|
230
|
+
if (this._geometryCount !== 0) {
|
231
|
+
lastRange = reservedRanges[reservedRanges.length - 1];
|
232
|
+
}
|
233
|
+
if (vertexCount === -1) {
|
234
|
+
range.vertexCount = geometry.getAttribute("position").count;
|
235
|
+
} else {
|
236
|
+
range.vertexCount = vertexCount;
|
237
|
+
}
|
238
|
+
if (lastRange === null) {
|
239
|
+
range.vertexStart = 0;
|
240
|
+
} else {
|
241
|
+
range.vertexStart = lastRange.vertexStart + lastRange.vertexCount;
|
242
|
+
}
|
243
|
+
if (geometry.getIndex() !== null) {
|
244
|
+
if (indexCount === -1) {
|
245
|
+
range.indexCount = geometry.getIndex().count;
|
246
|
+
} else {
|
247
|
+
range.indexCount = indexCount;
|
165
248
|
}
|
166
|
-
if (
|
167
|
-
|
168
|
-
|
249
|
+
if (lastRange === null) {
|
250
|
+
range.indexStart = 0;
|
251
|
+
} else {
|
252
|
+
range.indexStart = lastRange.indexStart + lastRange.indexCount;
|
169
253
|
}
|
170
|
-
const idArray = this._maxGeometryCount > 65536 ? new Uint32Array(this._maxVertexCount) : new Uint16Array(this._maxVertexCount);
|
171
|
-
this.geometry.setAttribute("id", new BufferAttribute(idArray, 1));
|
172
|
-
this._geometryInitialized = true;
|
173
254
|
}
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
const
|
178
|
-
this.
|
179
|
-
this._vertexCounts
|
180
|
-
|
181
|
-
|
182
|
-
|
255
|
+
if (range.indexStart !== -1 && range.indexStart + range.indexCount > this._maxIndexCount || range.vertexStart + range.vertexCount > this._maxVertexCount) {
|
256
|
+
throw new Error("BatchedMesh: Reserved space request exceeds the maximum buffer size.");
|
257
|
+
}
|
258
|
+
const indexCounts = this._indexCounts;
|
259
|
+
const indexStarts = this._indexStarts;
|
260
|
+
const vertexCounts = this._vertexCounts;
|
261
|
+
const vertexStarts = this._vertexStarts;
|
262
|
+
const visible = this._visible;
|
263
|
+
const active = this._active;
|
264
|
+
const matricesTexture = this._matricesTexture;
|
265
|
+
const matrices = this._matrices;
|
266
|
+
const matricesArray = this._matricesTexture.image.data;
|
267
|
+
visible.push(true);
|
268
|
+
active.push(true);
|
269
|
+
const geometryId = this._geometryCount;
|
270
|
+
this._geometryCount++;
|
271
|
+
matrices.push(new Matrix4());
|
272
|
+
_identityMatrix.toArray(matricesArray, geometryId * 16);
|
273
|
+
matricesTexture.needsUpdate = true;
|
274
|
+
reservedRanges.push(range);
|
275
|
+
vertexStarts.push(range.vertexStart);
|
276
|
+
vertexCounts.push(range.vertexCount);
|
277
|
+
if (geometry.getIndex() !== null) {
|
278
|
+
indexStarts.push(range.indexCount);
|
279
|
+
indexCounts.push(range.indexCount);
|
280
|
+
}
|
281
|
+
const idAttribute = this.geometry.getAttribute(ID_ATTR_NAME);
|
282
|
+
for (let i = 0; i < range.vertexCount; i++) {
|
283
|
+
idAttribute.setX(range.vertexStart + i, geometryId);
|
284
|
+
}
|
285
|
+
idAttribute.needsUpdate = true;
|
286
|
+
this.setGeometryAt(geometryId, geometry);
|
287
|
+
return geometryId;
|
288
|
+
}
|
289
|
+
/**
|
290
|
+
* @deprecated use `addGeometry` instead.
|
291
|
+
*/
|
292
|
+
applyGeometry(geometry) {
|
293
|
+
return this.addGeometry(geometry);
|
294
|
+
}
|
295
|
+
setGeometryAt(id, geometry) {
|
296
|
+
if (id >= this._geometryCount) {
|
297
|
+
throw new Error("BatchedMesh: Maximum geometry count reached.");
|
183
298
|
}
|
184
|
-
this.
|
185
|
-
this.
|
186
|
-
|
299
|
+
this._validateGeometry(geometry);
|
300
|
+
const range = this._reservedRanges[id];
|
301
|
+
if (geometry.getIndex() !== null && geometry.getIndex().count > range.indexCount || geometry.attributes.position.count > range.vertexCount) {
|
302
|
+
throw new Error("BatchedMesh: Reserved space not large enough for provided geometry.");
|
303
|
+
}
|
304
|
+
const batchGeometry = this.geometry;
|
305
|
+
const srcPositionAttribute = geometry.getAttribute("position");
|
306
|
+
const hasIndex = batchGeometry.getIndex() !== null;
|
307
|
+
const dstIndex = batchGeometry.getIndex();
|
308
|
+
const srcIndex = geometry.getIndex();
|
309
|
+
const vertexStart = range.vertexStart;
|
310
|
+
const vertexCount = range.vertexCount;
|
311
|
+
for (const attributeName in batchGeometry.attributes) {
|
312
|
+
if (attributeName === ID_ATTR_NAME) {
|
313
|
+
continue;
|
314
|
+
}
|
187
315
|
const srcAttribute = geometry.getAttribute(attributeName);
|
188
|
-
const dstAttribute =
|
189
|
-
|
316
|
+
const dstAttribute = batchGeometry.getAttribute(attributeName);
|
317
|
+
copyAttributeData(srcAttribute, dstAttribute, vertexStart);
|
318
|
+
const itemSize = srcAttribute.itemSize;
|
319
|
+
for (let i = srcAttribute.count, l = vertexCount; i < l; i++) {
|
320
|
+
const index = vertexStart + i;
|
321
|
+
for (let c = 0; c < itemSize; c++) {
|
322
|
+
dstAttribute.setComponent(index, c, 0);
|
323
|
+
}
|
324
|
+
}
|
190
325
|
dstAttribute.needsUpdate = true;
|
191
326
|
}
|
327
|
+
this._vertexCounts[id] = srcPositionAttribute.count;
|
192
328
|
if (hasIndex) {
|
329
|
+
const indexStart = range.indexStart;
|
193
330
|
for (let i = 0; i < srcIndex.count; i++) {
|
194
|
-
dstIndex.setX(
|
331
|
+
dstIndex.setX(indexStart + i, vertexStart + srcIndex.getX(i));
|
332
|
+
}
|
333
|
+
for (let i = srcIndex.count, l = range.indexCount; i < l; i++) {
|
334
|
+
dstIndex.setX(indexStart + i, vertexStart);
|
195
335
|
}
|
196
|
-
this._indexCount += srcIndex.count;
|
197
336
|
dstIndex.needsUpdate = true;
|
337
|
+
this._indexCounts[id] = srcIndex.count;
|
198
338
|
}
|
199
|
-
|
200
|
-
this._geometryCount++;
|
201
|
-
const idAttribute = this.geometry.getAttribute("id");
|
202
|
-
for (let i = 0; i < srcPositionAttribute.count; i++) {
|
203
|
-
idAttribute.setX(this._vertexCount + i, geometryId);
|
204
|
-
}
|
205
|
-
idAttribute.needsUpdate = true;
|
206
|
-
this._vertexCount += srcPositionAttribute.count;
|
207
|
-
this._matrices.push(new Matrix4());
|
208
|
-
_identityMatrix.toArray((_a = this._matricesArray) != null ? _a : void 0, geometryId * 16);
|
209
|
-
this._matricesTexture.needsUpdate = true;
|
210
|
-
return geometryId;
|
339
|
+
return id;
|
211
340
|
}
|
212
341
|
deleteGeometry(geometryId) {
|
213
|
-
|
342
|
+
const active = this._active;
|
343
|
+
const matricesTexture = this._matricesTexture;
|
344
|
+
const matricesArray = matricesTexture.image.data;
|
345
|
+
if (geometryId >= active.length || active[geometryId] === false) {
|
214
346
|
return this;
|
215
347
|
}
|
216
|
-
|
217
|
-
_zeroScaleMatrix.toArray(
|
218
|
-
|
348
|
+
active[geometryId] = false;
|
349
|
+
_zeroScaleMatrix.toArray(matricesArray, geometryId * 16);
|
350
|
+
matricesTexture.needsUpdate = true;
|
219
351
|
return this;
|
220
352
|
}
|
221
353
|
optimize() {
|
222
|
-
|
354
|
+
throw new Error("BatchedMesh: Optimize function not implemented.");
|
223
355
|
}
|
224
356
|
setMatrixAt(geometryId, matrix) {
|
225
|
-
|
357
|
+
const visible = this._visible;
|
358
|
+
const active = this._active;
|
359
|
+
const matricesTexture = this._matricesTexture;
|
360
|
+
const matrices = this._matrices;
|
361
|
+
const matricesArray = matricesTexture.image.data;
|
362
|
+
if (geometryId >= matrices.length || active[geometryId] === false) {
|
226
363
|
return this;
|
227
364
|
}
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
this._matricesTexture.needsUpdate = true;
|
365
|
+
if (visible[geometryId] === true) {
|
366
|
+
matrix.toArray(matricesArray, geometryId * 16);
|
367
|
+
matricesTexture.needsUpdate = true;
|
232
368
|
}
|
369
|
+
matrices[geometryId].copy(matrix);
|
233
370
|
return this;
|
234
371
|
}
|
235
372
|
getMatrixAt(geometryId, matrix) {
|
236
|
-
|
373
|
+
const matrices = this._matrices;
|
374
|
+
const active = this._active;
|
375
|
+
if (geometryId >= matrices.length || active[geometryId] === false) {
|
237
376
|
return matrix;
|
238
377
|
}
|
239
|
-
return matrix.copy(
|
378
|
+
return matrix.copy(matrices[geometryId]);
|
240
379
|
}
|
241
|
-
setVisibleAt(geometryId,
|
242
|
-
|
380
|
+
setVisibleAt(geometryId, value) {
|
381
|
+
const visible = this._visible;
|
382
|
+
const active = this._active;
|
383
|
+
const matricesTexture = this._matricesTexture;
|
384
|
+
const matrices = this._matrices;
|
385
|
+
const matricesArray = matricesTexture.image.data;
|
386
|
+
if (geometryId >= visible.length || active[geometryId] === false || visible[geometryId] === value) {
|
243
387
|
return this;
|
244
388
|
}
|
245
|
-
if (
|
246
|
-
|
247
|
-
}
|
248
|
-
if (visible === true) {
|
249
|
-
this._matrices[geometryId].toArray(this._matricesArray, geometryId * 16);
|
389
|
+
if (value === true) {
|
390
|
+
matrices[geometryId].toArray(matricesArray, geometryId * 16);
|
250
391
|
} else {
|
251
|
-
_zeroScaleMatrix.toArray(
|
392
|
+
_zeroScaleMatrix.toArray(matricesArray, geometryId * 16);
|
252
393
|
}
|
253
|
-
|
254
|
-
|
394
|
+
matricesTexture.needsUpdate = true;
|
395
|
+
visible[geometryId] = value;
|
255
396
|
return this;
|
256
397
|
}
|
257
398
|
getVisibleAt(geometryId) {
|
258
|
-
|
399
|
+
const visible = this._visible;
|
400
|
+
const active = this._active;
|
401
|
+
if (geometryId >= visible.length || active[geometryId] === false) {
|
259
402
|
return false;
|
260
403
|
}
|
261
|
-
return
|
404
|
+
return visible[geometryId];
|
262
405
|
}
|
263
|
-
|
264
|
-
|
265
|
-
|
406
|
+
raycast() {
|
407
|
+
console.warn("BatchedMesh: Raycast function not implemented.");
|
408
|
+
}
|
409
|
+
copy() {
|
410
|
+
throw new Error("BatchedMesh: Copy function not implemented.");
|
266
411
|
}
|
267
|
-
toJSON(
|
268
|
-
|
412
|
+
toJSON() {
|
413
|
+
throw new Error("BatchedMesh: toJSON function not implemented.");
|
269
414
|
}
|
270
415
|
dispose() {
|
271
|
-
var _a;
|
272
416
|
this.geometry.dispose();
|
273
|
-
|
417
|
+
this._matricesTexture.dispose();
|
274
418
|
this._matricesTexture = null;
|
275
419
|
return this;
|
276
420
|
}
|