Skip to content

Commit 6e05533

Browse files
author
devsh
committed
lay out separate geomtries along the X-axis
1 parent 0144b2d commit 6e05533

File tree

1 file changed

+27
-11
lines changed

1 file changed

+27
-11
lines changed

12_MeshLoaders/main.cpp

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,13 @@ class MeshLoadersApp final : public MonoWindowApplication, public BuiltinResourc
268268
}
269269
if (geometries.empty())
270270
return false;
271-
272-
auto bound = hlsl::shapes::AABB<3,double>::create();
271+
272+
using aabb_t = hlsl::shapes::AABB<3,double>;
273+
auto printAABB = [&](const aabb_t& aabb, const char* extraMsg="")->void
274+
{
275+
m_logger->log("%s AABB is (%f,%f,%f) -> (%f,%f,%f)",ILogger::ELL_INFO,extraMsg,aabb.minVx.x,aabb.minVx.y,aabb.minVx.z,aabb.maxVx.x,aabb.maxVx.y,aabb.maxVx.z);
276+
};
277+
auto bound = aabb_t::create();
273278
// convert the geometries
274279
{
275280
smart_refctd_ptr<CAssetConverter> converter = CAssetConverter::create({.device=m_device.get()});
@@ -344,36 +349,47 @@ class MeshLoadersApp final : public MonoWindowApplication, public BuiltinResourc
344349
return false;
345350
}
346351
}
347-
352+
353+
auto tmp = hlsl::float32_t4x3(
354+
hlsl::float32_t3(1,0,0),
355+
hlsl::float32_t3(0,1,0),
356+
hlsl::float32_t3(0,0,1),
357+
hlsl::float32_t3(0,0,0)
358+
);
359+
core::vector<hlsl::float32_t3x4> worldTforms;
348360
const auto& converted = reservation.getGPUObjects<ICPUPolygonGeometry>();
349361
for (const auto& geom : converted)
350362
{
351-
geom.value->visitAABB([&bound](const auto& aabb)->void
363+
geom.value->visitAABB([&bound,&worldTforms,&tmp,&printAABB](const auto& aabb)->void
352364
{
353365
hlsl::shapes::AABB<3,double> promoted;
354366
promoted.minVx = aabb.minVx;
355367
promoted.maxVx = aabb.maxVx;
356-
bound = hlsl::shapes::util::union_(promoted,bound);
368+
printAABB(promoted,"Geometry");
369+
tmp[3].x += promoted.getExtent().x;
370+
const auto promotedWorld = hlsl::float64_t3x4(worldTforms.emplace_back(hlsl::transpose(tmp)));
371+
const auto transformed = hlsl::shapes::util::transform(promotedWorld,promoted);
372+
printAABB(transformed,"Transformed");
373+
bound = hlsl::shapes::util::union_(transformed,bound);
357374
}
358375
);
359376
}
377+
printAABB(bound,"Total");
360378
if (!m_renderer->addGeometries({ &converted.front().get(),converted.size() }))
361379
return false;
380+
381+
auto worlTformsIt = worldTforms.begin();
362382
for (const auto& geo : m_renderer->getGeometries())
363383
m_renderer->m_instances.push_back({
364-
.world = hlsl::float32_t3x4(
365-
hlsl::float32_t4(1,0,0,0),
366-
hlsl::float32_t4(0,1,0,0),
367-
hlsl::float32_t4(0,0,1,0)
368-
),
384+
.world = *(worlTformsIt++),
369385
.packedGeo = &geo
370386
});
371387
}
372388

373389
// get scene bounds and reset camera
374390
{
375391
const double distance = 0.05;
376-
const auto diagonal = bound.maxVx-bound.minVx;
392+
const auto diagonal = bound.getExtent();
377393
{
378394
const auto measure = hlsl::length(diagonal);
379395
const auto aspectRatio = float(m_window->getWidth())/float(m_window->getHeight());

0 commit comments

Comments
 (0)