gltfio: fix issue with bounding box computation.
If the client opts in to "recomputeBoundingBoxes", then we manually compute a bounding box that ignores the glTF min / max annotations. This computation was erroneously including the transform of the injected root node, which is not part of the model. This could cause a problem when creating the asset, then immediately positioning it with its injected root node before the ResourceLoader is done downloading vertex buffers.
This commit is contained in:
@@ -537,6 +537,16 @@ void ResourceLoader::updateBoundingBoxes(details::FFilamentAsset* asset) const {
|
||||
auto& rm = mConfig.engine->getRenderableManager();
|
||||
auto& tm = mConfig.engine->getTransformManager();
|
||||
|
||||
// The purpose of the root node is to give the client a place for custom transforms.
|
||||
// Since it is not part of the source model, it should be ignored when computing the
|
||||
// bounding box.
|
||||
TransformManager::Instance root = tm.getInstance(asset->getRoot());
|
||||
std::vector<Entity> modelRoots(tm.getChildCount(root));
|
||||
tm.getChildren(root, modelRoots.data(), modelRoots.size());
|
||||
for (auto e : modelRoots) {
|
||||
tm.setParent(tm.getInstance(e), 0);
|
||||
}
|
||||
|
||||
auto computeBoundingBox = [&](const cgltf_primitive& prim) {
|
||||
Aabb aabb;
|
||||
for (cgltf_size slot = 0; slot < prim.attributes_count; slot++) {
|
||||
@@ -588,6 +598,11 @@ void ResourceLoader::updateBoundingBoxes(details::FFilamentAsset* asset) const {
|
||||
assetBounds.max = max(assetBounds.max, maxpt);
|
||||
}
|
||||
}
|
||||
|
||||
for (auto e : modelRoots) {
|
||||
tm.setParent(tm.getInstance(e), root);
|
||||
}
|
||||
|
||||
asset->mBoundingBox = assetBounds;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user