From 22dcdc770fefefb20a7b8a8fba27214a003ddc62 Mon Sep 17 00:00:00 2001 From: Philip Rideout Date: Tue, 2 Jul 2019 10:48:01 -0700 Subject: [PATCH] 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. --- libs/gltfio/src/ResourceLoader.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/libs/gltfio/src/ResourceLoader.cpp b/libs/gltfio/src/ResourceLoader.cpp index be0a556c91..8213146b77 100644 --- a/libs/gltfio/src/ResourceLoader.cpp +++ b/libs/gltfio/src/ResourceLoader.cpp @@ -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 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; }