Если вы ссылаетесь на исходный код viewer.impl.fitToView()
, есть пара функций, которые он использует для вычисления ограничивающих рамок, вот часть кода:
function getObjectBound2D(viewer, objectId) {
var model = viewer.model;
// This doesn't guarantee that an object tree will be created but it will be pretty likely
var bounds, bc, i;
if (model.is2d()) {
bounds = new THREE.Box3();
// move this next one up into the calling method
bc = new avp.BoundsCallback(bounds);
var dbId2fragId = model.getData().fragments.dbId2fragId;
var fragIds = dbId2fragId[objectId];
// fragId is either a single vertex buffer or an array of vertex buffers
if (Array.isArray(fragIds)) {
for (var j = 0; j < fragIds.length; j++) {
// go through each vertex buffer, looking for the object id
find2DBounds(model, fragIds[j], objectId, bc);
}
} else if (typeof fragIds === 'number') {
// go through the specific vertex buffer, looking for the object id
find2DBounds(model, fragIds, objectId, bc);
}
// should have some real box at this point; check
if (!bounds.empty()) {
return bounds;
}
}
function find2DBounds(model, fragId, dbId, bc) {
var mesh = model.getFragmentList().getVizmesh(fragId);
var vbr = new avp.VertexBufferReader(mesh.geometry);
vbr.enumGeomsForObject(dbId, bc);
}
function find2DLayerBounds(model, fragId, bc) {
var mesh = model.getFragmentList().getVizmesh(fragId);
var vbr = new avp.VertexBufferReader(mesh.geometry);
var visibleLayerIds = that.getVisibleLayerIds();
vbr.enumGeomsForVisibleLayer(visibleLayerIds, bc);
}