added best bbox calc using instance world space xforms to do zoomextents

This commit is contained in:
Harvey Fong 2025-08-01 08:13:43 -06:00
parent 5c593ed0f9
commit 3a618bb112

View File

@ -171,6 +171,7 @@ The 't' field in the snapshot's 's.id' dictionary indicates the type of snapshot
*/ */
#include <iostream> // For input/output operations (cout, cin, etc.) #include <iostream> // For input/output operations (cout, cin, etc.)
#include <limits> // For std::numeric_limits
// Bella SDK includes - external libraries for 3D rendering // Bella SDK includes - external libraries for 3D rendering
#include "../bella_engine_sdk/src/bella_sdk/bella_scene.h" // For creating and manipulating 3D scenes in Bella #include "../bella_engine_sdk/src/bella_sdk/bella_scene.h" // For creating and manipulating 3D scenes in Bella
@ -352,7 +353,7 @@ int DL_main(dl::Args& args) {
std::vector<std::vector<oom::vmax::RGBA>> vmaxPalettes; // one palette per model std::vector<std::vector<oom::vmax::RGBA>> vmaxPalettes; // one palette per model
std::vector<std::array<oom::vmax::Material, 8>> vmaxMaterials; // one material per model std::vector<std::array<oom::vmax::Material, 8>> vmaxMaterials; // one material per model
oom::bella::defaultScene2025(belScene); // create the basic scene elements in Bella //oom::bella::defaultScene2025(belScene); // create the basic scene elements in Bella
// Loop over each model defined in scene.json and process the first instance // Loop over each model defined in scene.json and process the first instance
// This will be out canonical models, not instances // This will be out canonical models, not instances
@ -483,6 +484,47 @@ int DL_main(dl::Args& args) {
} }
} }
// Initialize bbox to "inverted infinity" so first point will always expand it
dl::Aabb sceneBbox;
sceneBbox.min = dl::Pos3::make(std::numeric_limits<double>::max(),
std::numeric_limits<double>::max(),
std::numeric_limits<double>::max());
sceneBbox.max = dl::Pos3::make(std::numeric_limits<double>::lowest(),
std::numeric_limits<double>::lowest(),
std::numeric_limits<double>::lowest());
int voxelCount = 0;
//
auto worldPaths = belScene.world().paths(); // Scene Tree Loop
for ( auto eachPath : worldPaths )
{
auto eachLeaf = eachPath.leaf();
if ( !eachLeaf.isTypeOf( "instancer" ) )
continue;
voxelCount++;
auto instances = eachLeaf["steps"][0]["instances"].asBufferT<dl::Mat4f>(); // just need count
for (dl::UInt i = 0; i < instances.count; ++i) {
// Since we are dealing with 1x1x1 voxels
// approximate by using center of voxel instance instead of 8 corners
// for bbox calculation
auto instanceXform = eachPath.transform(0.0,i); // feed InstanceIdx
auto instancePos = dl::math::translation(instanceXform); // Extract translation directly
// No branch - always expand (faster for large instance counts)
if (instancePos.x < sceneBbox.min.x) sceneBbox.min.x = instancePos.x;
if (instancePos.y < sceneBbox.min.y) sceneBbox.min.y = instancePos.y;
if (instancePos.z < sceneBbox.min.z) sceneBbox.min.z = instancePos.z;
if (instancePos.x > sceneBbox.max.x) sceneBbox.max.x = instancePos.x;
if (instancePos.y > sceneBbox.max.y) sceneBbox.max.y = instancePos.y;
if (instancePos.z > sceneBbox.max.z) sceneBbox.max.z = instancePos.z;
}
}
auto center = ( sceneBbox.min.v3 + sceneBbox.max.v3 ) * 0.5;
auto radius =dl::math::norm( sceneBbox.max - sceneBbox.min ) * 0.5;
dl::bella_sdk::zoomExtents(belScene.cameraPath(), dl::Vec3{center.x, center.y, center.z}, radius);
// Write Bella File .bsz=compressed .bsa=ascii .bsx=binary // Write Bella File .bsz=compressed .bsa=ascii .bsx=binary
belScene.write(bszName.buf()); belScene.write(bszName.buf());
} }