Skip to content

Commit

Permalink
Traktor: Removed vista from heightfield editor. Improved heightfield …
Browse files Browse the repository at this point in the history
…to mesh converter.
  • Loading branch information
apistol78 committed Mar 4, 2024
1 parent 557cc43 commit c211c00
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 20 deletions.
71 changes: 57 additions & 14 deletions code/Heightfield/Editor/ConvertHeightfield.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand All @@ -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);
}
}
}

Expand Down
6 changes: 0 additions & 6 deletions code/Heightfield/Editor/HeightfieldAssetEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"));

Expand Down

0 comments on commit c211c00

Please sign in to comment.