From c211c006fa19034656dc45d9ba4baf6c2aa6689a Mon Sep 17 00:00:00 2001 From: apistol78 Date: Mon, 4 Mar 2024 11:30:44 +0100 Subject: [PATCH] Traktor: Removed vista from heightfield editor. Improved heightfield to mesh converter. --- .../Heightfield/Editor/ConvertHeightfield.cpp | 71 +++++++++++++++---- .../Editor/HeightfieldAssetEditor.cpp | 6 -- 2 files changed, 57 insertions(+), 20 deletions(-) diff --git a/code/Heightfield/Editor/ConvertHeightfield.cpp b/code/Heightfield/Editor/ConvertHeightfield.cpp index e2a7cb53b1..4942f97b1a 100644 --- a/code/Heightfield/Editor/ConvertHeightfield.cpp +++ b/code/Heightfield/Editor/ConvertHeightfield.cpp @@ -82,8 +82,11 @@ Ref< model::Model > ConvertHeightfield::convert(const Heightfield* heightfield, const int32_t offset = iz * outputSize; for (int32_t ix = 0; ix < outputSize - 1; ++ix) { + const int32_t gx = ix0 + ix * step; + const int32_t gz = iz0 + iz * step; + float wx, wz; - heightfield->gridToWorld(ix0 + ix * step, iz0 + iz * step, wx, wz); + heightfield->gridToWorld(gx, gz, wx, wz); if (!heightfield->getWorldCut(wx, wz)) continue; @@ -94,6 +97,27 @@ Ref< model::Model > ConvertHeightfield::convert(const Heightfield* heightfield, if (!heightfield->getWorldCut(wx, wz + step)) continue; + const float heights[] = + { + heightfield->getGridHeightNearest(gx, gz), + heightfield->getGridHeightNearest(gx + step, gz), + heightfield->getGridHeightNearest(gx + step, gz + step), + heightfield->getGridHeightNearest(gx, gz + step) + }; + + const float ch = (heights[0] + heights[1] + heights[2] + heights[3]) / 4.0f; + + const float dh[] = + { + std::abs(ch - heights[0]), + std::abs(ch - heights[1]), + std::abs(ch - heights[2]), + std::abs(ch - heights[3]) + }; + + const auto it = std::max_element(&dh[0], &dh[4]); + const int32_t mdhi = (int32_t)std::distance(&dh[0], it); + const int32_t indices[] = { offset + ix, @@ -102,19 +126,38 @@ Ref< model::Model > ConvertHeightfield::convert(const Heightfield* heightfield, offset + ix + outputSize }; - polygon.clearVertices(); - polygon.setMaterial(0); - polygon.addVertex(indices[0]); - polygon.addVertex(indices[1]); - polygon.addVertex(indices[3]); - model->addPolygon(polygon); - - polygon.clearVertices(); - polygon.setMaterial(0); - polygon.addVertex(indices[1]); - polygon.addVertex(indices[2]); - polygon.addVertex(indices[3]); - model->addPolygon(polygon); + if (mdhi == 0 || mdhi == 2) + { + polygon.clearVertices(); + polygon.setMaterial(0); + polygon.addVertex(indices[0]); + polygon.addVertex(indices[1]); + polygon.addVertex(indices[3]); + model->addPolygon(polygon); + + polygon.clearVertices(); + polygon.setMaterial(0); + polygon.addVertex(indices[1]); + polygon.addVertex(indices[2]); + polygon.addVertex(indices[3]); + model->addPolygon(polygon); + } + else + { + polygon.clearVertices(); + polygon.setMaterial(0); + polygon.addVertex(indices[0]); + polygon.addVertex(indices[1]); + polygon.addVertex(indices[2]); + model->addPolygon(polygon); + + polygon.clearVertices(); + polygon.setMaterial(0); + polygon.addVertex(indices[0]); + polygon.addVertex(indices[2]); + polygon.addVertex(indices[3]); + model->addPolygon(polygon); + } } } diff --git a/code/Heightfield/Editor/HeightfieldAssetEditor.cpp b/code/Heightfield/Editor/HeightfieldAssetEditor.cpp index e8da58530c..62d4b53726 100644 --- a/code/Heightfield/Editor/HeightfieldAssetEditor.cpp +++ b/code/Heightfield/Editor/HeightfieldAssetEditor.cpp @@ -129,12 +129,6 @@ bool HeightfieldAssetEditor::create(ui::Widget* parent, db::Instance* instance, Ref< ui::Static > staticExtentUnit = new ui::Static(); staticExtentUnit->create(containerFields, i18n::Text(L"HEIGHTFIELD_ASSET_EXTENT_UNIT")); - Ref< ui::Static > staticVista = new ui::Static(); - staticVista->create(containerFields, i18n::Text(L"HEIGHTFIELD_ASSET_VISTA")); - - Ref< ui::Static > staticVistaUnit = new ui::Static(); - staticVistaUnit->create(containerFields, i18n::Text(L"HEIGHTFIELD_ASSET_VISTA_UNIT")); - Ref< ui::Static > staticSize = new ui::Static(); staticSize->create(containerFields, i18n::Text(L"HEIGHTFIELD_ASSET_SIZE"));