Skip to content

Commit 8f6c7bc

Browse files
author
devsh
committed
get the spanner PLY loading!
1 parent 5929be1 commit 8f6c7bc

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

12_MeshLoaders/main.cpp

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,21 @@ class MeshLoadersApp final : public MonoWindowApplication, public BuiltinResourc
100100
}
101101
// late latch input
102102
{
103+
bool reload = false;
103104
camera.beginInputProcessing(nextPresentationTimestamp);
104105
mouse.consumeEvents([&](const IMouseEventChannel::range_t& events) -> void { camera.mouseProcess(events); }, m_logger.get());
105106
keyboard.consumeEvents([&](const IKeyboardEventChannel::range_t& events) -> void
106107
{
108+
for (const auto& event : events)
109+
if (event.keyCode==E_KEY_CODE::EKC_R && event.action==SKeyboardEvent::ECA_RELEASED)
110+
reload = true;
107111
camera.keyboardProcess(events);
108112
},
109113
m_logger.get()
110114
);
111115
camera.endInputProcessing(nextPresentationTimestamp);
116+
if (reload)
117+
reloadModel();
112118
}
113119
// draw scene
114120
{
@@ -239,6 +245,7 @@ class MeshLoadersApp final : public MonoWindowApplication, public BuiltinResourc
239245

240246
//! load the geometry
241247
IAssetLoader::SAssetLoadParams params = {};
248+
params.logger = m_logger.get();
242249
params.meshManipulatorOverride = nullptr; // TODO
243250
auto bundle = m_assetMgr->getAsset(m_modelPath,params);
244251
if (bundle.getContents().empty())
@@ -263,6 +270,7 @@ class MeshLoadersApp final : public MonoWindowApplication, public BuiltinResourc
263270
//! cache results -- speeds up mesh generation on second run
264271
m_qnc->saveCacheToFile<EF_R8G8B8_SNORM>(m_system.get(),sharedOutputCWD/"../../tmp/normalCache888.sse");
265272

273+
auto bound = hlsl::shapes::AABB<3,double>::create();
266274
// convert the geometries
267275
{
268276
smart_refctd_ptr<CAssetConverter> converter = CAssetConverter::create({.device=m_device.get()});
@@ -339,11 +347,45 @@ class MeshLoadersApp final : public MonoWindowApplication, public BuiltinResourc
339347
}
340348

341349
const auto& converted = reservation.getGPUObjects<ICPUPolygonGeometry>();
350+
for (const auto& geom : converted)
351+
{
352+
geom.value->visitAABB([&bound](const auto& aabb)->void
353+
{
354+
hlsl::shapes::AABB<3,double> promoted;
355+
promoted.minVx = aabb.minVx;
356+
promoted.maxVx = aabb.maxVx;
357+
bound = hlsl::shapes::util::union_(promoted,bound);
358+
}
359+
);
360+
}
342361
if (!m_renderer->addGeometries({ &converted.front().get(),converted.size() }))
343362
return false;
363+
for (const auto& geo : m_renderer->getGeometries())
364+
m_renderer->m_instances.push_back({
365+
.world = hlsl::float32_t3x4(
366+
hlsl::float32_t4(1,0,0,0),
367+
hlsl::float32_t4(0,1,0,0),
368+
hlsl::float32_t4(0,0,1,0)
369+
),
370+
.packedGeo = &geo
371+
});
344372
}
345373

346-
// TODO: get scene bounds and reset camera
374+
// get scene bounds and reset camera
375+
{
376+
const double distance = 0.05;
377+
const auto diagonal = bound.maxVx-bound.minVx;
378+
{
379+
const auto measure = hlsl::length(diagonal);
380+
const auto aspectRatio = float(m_window->getWidth())/float(m_window->getHeight());
381+
camera.setProjectionMatrix(core::matrix4SIMD::buildProjectionMatrixPerspectiveFovRH(1.2f,aspectRatio,distance*measure*0.1,measure*4.0));
382+
camera.setMoveSpeed(measure*0.04);
383+
}
384+
const auto pos = bound.maxVx+diagonal*distance;
385+
camera.setPosition(vectorSIMDf(pos.x,pos.y,pos.z));
386+
const auto center = (bound.minVx+bound.maxVx)*0.5;
387+
camera.setTarget(vectorSIMDf(center.x,center.y,center.z));
388+
}
347389

348390
// TODO: write out the geometry
349391

0 commit comments

Comments
 (0)