three-zoo 0.11.3 → 0.11.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/dist/index.d.ts +3 -0
- package/dist/index.js +162 -2
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/dist/instancedMeshPool/InstancedMeshGroup.d.ts +8 -0
- package/dist/instancedMeshPool/InstancedMeshInstance.d.ts +21 -0
- package/dist/instancedMeshPool/InstancedMeshPool.d.ts +27 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
export { DualFovCamera } from "./DualFovCamera";
|
|
2
|
+
export { InstancedMeshGroup } from "./instancedMeshPool/InstancedMeshGroup";
|
|
3
|
+
export { InstancedMeshInstance } from "./instancedMeshPool/InstancedMeshInstance";
|
|
4
|
+
export { InstancedMeshPool } from "./instancedMeshPool/InstancedMeshPool";
|
|
2
5
|
export { BasicToPhysicalConverter } from "./materialConverters/BasicToPhysicalConverter";
|
|
3
6
|
export { StandardToBasicConverter } from "./materialConverters/StandardToBasicConverter";
|
|
4
7
|
export { StandardToLambertConverter } from "./materialConverters/StandardToLambertConverter";
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PerspectiveCamera, MathUtils, Vector3, MeshPhysicalMaterial, Color, MeshBasicMaterial, MeshLambertMaterial, MeshPhongMaterial, MeshToonMaterial, Mesh, BufferAttribute, AnimationMixer, HemisphereLight, RGBAFormat, DirectionalLight, Box3, Spherical } from 'three';
|
|
1
|
+
import { PerspectiveCamera, MathUtils, Vector3, Object3D, Matrix4, Quaternion, InstancedMesh, MeshPhysicalMaterial, Color, MeshBasicMaterial, MeshLambertMaterial, MeshPhongMaterial, MeshToonMaterial, Mesh, BufferAttribute, AnimationMixer, HemisphereLight, RGBAFormat, DirectionalLight, Box3, Spherical } from 'three';
|
|
2
2
|
|
|
3
3
|
/** Default horizontal field of view in degrees */
|
|
4
4
|
const DEFAULT_HORIZONTAL_FOV = 90;
|
|
@@ -242,6 +242,166 @@ class DualFovCamera extends PerspectiveCamera {
|
|
|
242
242
|
}
|
|
243
243
|
}
|
|
244
244
|
|
|
245
|
+
class InstancedMeshGroup extends Object3D {
|
|
246
|
+
constructor(_private_instances) {
|
|
247
|
+
super();
|
|
248
|
+
this._private_instances = _private_instances;
|
|
249
|
+
}
|
|
250
|
+
flushTransform() {
|
|
251
|
+
this.updateWorldMatrix(true, false);
|
|
252
|
+
for (const instance of this._private_instances) {
|
|
253
|
+
instance.setTransform(this.matrixWorld);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
destroy() {
|
|
257
|
+
for (const instance of this._private_instances) {
|
|
258
|
+
instance.destroy();
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
class InstancedMeshInstance {
|
|
264
|
+
constructor(pool, entry, index) {
|
|
265
|
+
this._private_pool = pool;
|
|
266
|
+
this["entry"] = entry;
|
|
267
|
+
this.index = index;
|
|
268
|
+
this._private_matrix = new Matrix4();
|
|
269
|
+
this._private_position = new Vector3();
|
|
270
|
+
this._private_quaternion = new Quaternion();
|
|
271
|
+
this._private_scale = new Vector3(1, 1, 1);
|
|
272
|
+
}
|
|
273
|
+
setPosition(v) {
|
|
274
|
+
this._private_position.copy(v);
|
|
275
|
+
this._private_apply();
|
|
276
|
+
return this;
|
|
277
|
+
}
|
|
278
|
+
setPosition3f(x, y, z) {
|
|
279
|
+
this._private_position.set(x, y, z);
|
|
280
|
+
this._private_apply();
|
|
281
|
+
return this;
|
|
282
|
+
}
|
|
283
|
+
setQuaternion(q) {
|
|
284
|
+
this._private_quaternion.copy(q);
|
|
285
|
+
this._private_apply();
|
|
286
|
+
return this;
|
|
287
|
+
}
|
|
288
|
+
setQuaternion4f(x, y, z, w) {
|
|
289
|
+
this._private_quaternion.set(x, y, z, w);
|
|
290
|
+
this._private_apply();
|
|
291
|
+
return this;
|
|
292
|
+
}
|
|
293
|
+
setScale(v) {
|
|
294
|
+
this._private_scale.copy(v);
|
|
295
|
+
this._private_apply();
|
|
296
|
+
return this;
|
|
297
|
+
}
|
|
298
|
+
setScale3f(x, y, z) {
|
|
299
|
+
this._private_scale.set(x, y, z);
|
|
300
|
+
this._private_apply();
|
|
301
|
+
return this;
|
|
302
|
+
}
|
|
303
|
+
setTransform(m) {
|
|
304
|
+
m.decompose(this._private_position, this._private_quaternion, this._private_scale);
|
|
305
|
+
this._private_apply();
|
|
306
|
+
return this;
|
|
307
|
+
}
|
|
308
|
+
destroy() {
|
|
309
|
+
if (this.index === -1)
|
|
310
|
+
return;
|
|
311
|
+
this._private_pool.deallocate(this);
|
|
312
|
+
}
|
|
313
|
+
_private_apply() {
|
|
314
|
+
if (this.index === -1)
|
|
315
|
+
return;
|
|
316
|
+
this._private_matrix.compose(this._private_position, this._private_quaternion, this._private_scale);
|
|
317
|
+
this["entry"].mesh.setMatrixAt(this.index, this._private_matrix);
|
|
318
|
+
this._private_pool["notifyUpdate"](this["entry"]);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
const TEMP_MATRIX = new Matrix4();
|
|
323
|
+
class InstancedMeshPool {
|
|
324
|
+
constructor(options) {
|
|
325
|
+
var _a, _b;
|
|
326
|
+
this._private_scene = options.scene;
|
|
327
|
+
this._private_initialCapacity = (_a = options.initialCapacity) !== null && _a !== void 0 ? _a : 16;
|
|
328
|
+
this._private_capacityStep = (_b = options.capacityStep) !== null && _b !== void 0 ? _b : this._private_initialCapacity;
|
|
329
|
+
this._private_meshes = new Map();
|
|
330
|
+
}
|
|
331
|
+
allocate(geometry, material) {
|
|
332
|
+
const entry = this._private_getOrCreateEntry(geometry, material);
|
|
333
|
+
if (entry.count === entry.capacity) {
|
|
334
|
+
this._private_growEntry(entry);
|
|
335
|
+
}
|
|
336
|
+
const index = entry.count;
|
|
337
|
+
entry.count++;
|
|
338
|
+
const instance = new InstancedMeshInstance(this, entry, index);
|
|
339
|
+
instance.setScale3f(1, 1, 1);
|
|
340
|
+
entry.instances.set(index, instance);
|
|
341
|
+
entry.mesh.count = entry.count;
|
|
342
|
+
return instance;
|
|
343
|
+
}
|
|
344
|
+
deallocate(instance) {
|
|
345
|
+
if (instance.index === -1)
|
|
346
|
+
return;
|
|
347
|
+
const entry = instance["entry"];
|
|
348
|
+
const removedIndex = instance.index;
|
|
349
|
+
const lastIndex = entry.count - 1;
|
|
350
|
+
entry.instances.delete(removedIndex);
|
|
351
|
+
if (removedIndex !== lastIndex) {
|
|
352
|
+
// swap: move last to removed position
|
|
353
|
+
const lastInstance = entry.instances.get(lastIndex);
|
|
354
|
+
entry.mesh.getMatrixAt(lastIndex, TEMP_MATRIX);
|
|
355
|
+
entry.mesh.setMatrixAt(removedIndex, TEMP_MATRIX);
|
|
356
|
+
lastInstance.index = removedIndex;
|
|
357
|
+
entry.instances.delete(lastIndex);
|
|
358
|
+
entry.instances.set(removedIndex, lastInstance);
|
|
359
|
+
}
|
|
360
|
+
entry.count--;
|
|
361
|
+
entry.mesh.count = entry.count;
|
|
362
|
+
instance.index = -1;
|
|
363
|
+
this["notifyUpdate"](entry);
|
|
364
|
+
}
|
|
365
|
+
_private_getOrCreateEntry(geometry, material) {
|
|
366
|
+
const key = `${geometry.uuid}:${material.uuid}`;
|
|
367
|
+
let entry = this._private_meshes.get(key);
|
|
368
|
+
if (!entry) {
|
|
369
|
+
const mesh = new InstancedMesh(geometry, material, this._private_initialCapacity);
|
|
370
|
+
mesh.count = 0;
|
|
371
|
+
mesh.frustumCulled = false;
|
|
372
|
+
this._private_scene.add(mesh);
|
|
373
|
+
entry = {
|
|
374
|
+
mesh,
|
|
375
|
+
geometry,
|
|
376
|
+
material,
|
|
377
|
+
capacity: this._private_initialCapacity,
|
|
378
|
+
count: 0,
|
|
379
|
+
instances: new Map(),
|
|
380
|
+
};
|
|
381
|
+
this._private_meshes.set(key, entry);
|
|
382
|
+
}
|
|
383
|
+
return entry;
|
|
384
|
+
}
|
|
385
|
+
_private_growEntry(entry) {
|
|
386
|
+
const newCapacity = entry.capacity + this._private_capacityStep;
|
|
387
|
+
const newMesh = new InstancedMesh(entry.geometry, entry.material, newCapacity);
|
|
388
|
+
newMesh.frustumCulled = false;
|
|
389
|
+
const oldArray = entry.mesh.instanceMatrix.array;
|
|
390
|
+
const newArray = newMesh.instanceMatrix.array;
|
|
391
|
+
newArray.set(oldArray);
|
|
392
|
+
newMesh.instanceMatrix.needsUpdate = true;
|
|
393
|
+
this._private_scene.remove(entry.mesh);
|
|
394
|
+
entry.mesh.dispose();
|
|
395
|
+
this._private_scene.add(newMesh);
|
|
396
|
+
entry.mesh = newMesh;
|
|
397
|
+
entry.capacity = newCapacity;
|
|
398
|
+
entry.mesh.count = entry.count;
|
|
399
|
+
}
|
|
400
|
+
["notifyUpdate"](entry) {
|
|
401
|
+
entry.mesh.instanceMatrix.needsUpdate = true;
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
|
|
245
405
|
class BasicToPhysicalConverter {
|
|
246
406
|
static convert(material, options = {}) {
|
|
247
407
|
const config = Object.assign({ preserveName: true, copyUserData: true, disposeOriginal: false }, options);
|
|
@@ -1765,5 +1925,5 @@ class Sun extends DirectionalLight {
|
|
|
1765
1925
|
}
|
|
1766
1926
|
}
|
|
1767
1927
|
|
|
1768
|
-
export { BasicToPhysicalConverter, DualFovCamera, SceneTraversal, SkinnedMeshBaker, SkyLight, StandardToBasicConverter, StandardToLambertConverter, StandardToPhongConverter, StandardToPhysicalConverter, StandardToToonConverter, Sun };
|
|
1928
|
+
export { BasicToPhysicalConverter, DualFovCamera, InstancedMeshGroup, InstancedMeshInstance, InstancedMeshPool, SceneTraversal, SkinnedMeshBaker, SkyLight, StandardToBasicConverter, StandardToLambertConverter, StandardToPhongConverter, StandardToPhysicalConverter, StandardToToonConverter, Sun };
|
|
1769
1929
|
//# sourceMappingURL=index.js.map
|