playcanvas
Version:
Open-source WebGL/WebGPU 3D engine for the web
52 lines (51 loc) • 1.27 kB
JavaScript
import { BoundingBox } from "../../core/shape/bounding-box.js";
class Batch {
_aabb = new BoundingBox();
origMeshInstances;
meshInstance = null;
dynamic;
batchGroupId;
constructor(meshInstances, dynamic, batchGroupId) {
this.origMeshInstances = meshInstances;
this.dynamic = dynamic;
this.batchGroupId = batchGroupId;
}
destroy(scene, layers) {
if (this.meshInstance) {
this.removeFromLayers(scene, layers);
this.meshInstance.destroy();
this.meshInstance = null;
}
}
addToLayers(scene, layers) {
for (let i = 0; i < layers.length; i++) {
const layer = scene.layers.getLayerById(layers[i]);
if (layer) {
layer.addMeshInstances([this.meshInstance]);
}
}
}
removeFromLayers(scene, layers) {
for (let i = 0; i < layers.length; i++) {
const layer = scene.layers.getLayerById(layers[i]);
if (layer) {
layer.removeMeshInstances([this.meshInstance]);
}
}
}
// Updates bounding box for a batch
updateBoundingBox() {
this._aabb.copy(this.origMeshInstances[0].aabb);
for (let i = 1; i < this.origMeshInstances.length; i++) {
this._aabb.add(this.origMeshInstances[i].aabb);
}
this.meshInstance.aabb = this._aabb;
this.meshInstance._aabbVer = 0;
}
get model() {
return void 0;
}
}
export {
Batch
};