From 3a618bb1122104692d0251639fd653b8a92102f6 Mon Sep 17 00:00:00 2001 From: Harvey Fong Date: Fri, 1 Aug 2025 08:13:43 -0600 Subject: [PATCH] added best bbox calc using instance world space xforms to do zoomextents --- vmax2bella.cpp | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/vmax2bella.cpp b/vmax2bella.cpp index 4ec0ef7..1331971 100644 --- a/vmax2bella.cpp +++ b/vmax2bella.cpp @@ -171,6 +171,7 @@ The 't' field in the snapshot's 's.id' dictionary indicates the type of snapshot */ #include // For input/output operations (cout, cin, etc.) +#include // For std::numeric_limits // 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 @@ -352,7 +353,7 @@ int DL_main(dl::Args& args) { std::vector> vmaxPalettes; // one palette per model std::vector> 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 // 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::max(), + std::numeric_limits::max(), + std::numeric_limits::max()); + sceneBbox.max = dl::Pos3::make(std::numeric_limits::lowest(), + std::numeric_limits::lowest(), + std::numeric_limits::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(); // 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 belScene.write(bszName.buf()); }