From 8cc52a171ed2a5ab137baf20f66048893467f72f Mon Sep 17 00:00:00 2001 From: turanszkij Date: Sun, 5 Apr 2020 13:51:45 +0100 Subject: [PATCH] paint tool: sculpt mode update --- Editor/PaintToolWindow.cpp | 47 ++++++++++++++++++++++++++------------ 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/Editor/PaintToolWindow.cpp b/Editor/PaintToolWindow.cpp index 918c6ea74..3f29a30ea 100644 --- a/Editor/PaintToolWindow.cpp +++ b/Editor/PaintToolWindow.cpp @@ -496,6 +496,16 @@ void PaintToolWindow::Update(float dt) bool rebuild = false; if (painting) { + XMVECTOR averageNormal = XMVectorZero(); + struct PaintVert + { + size_t ind; + float affection; + }; + static std::vector paintindices; + paintindices.clear(); + paintindices.reserve(mesh->vertex_positions.size()); + for (size_t j = 0; j < mesh->vertex_positions.size(); ++j) { XMVECTOR P, N; @@ -522,23 +532,32 @@ void PaintToolWindow::Update(float dt) const float dist = XMVectorGetX(XMVector2Length(C - P)); if (z >= 0 && z <= 1 && dist <= radius) { - RecordHistory(true); - XMVECTOR PL = XMLoadFloat3(&mesh->vertex_positions[j]); - const XMVECTOR NL = XMLoadFloat3(&mesh->vertex_normals[j]); + averageNormal += N; const float affection = amount * std::powf(1 - (dist / radius), falloff); - switch (mode) - { - case MODE_SCULPTING_ADD: - PL += NL * affection; - break; - case MODE_SCULPTING_SUBTRACT: - PL -= NL * affection; - break; - } - XMStoreFloat3(&mesh->vertex_positions[j], PL); - rebuild = true; + paintindices.push_back({ j, affection }); } } + + if (!paintindices.empty()) + { + RecordHistory(true); + rebuild = true; + averageNormal = XMVector3Normalize(averageNormal); + } + for (auto& x : paintindices) + { + XMVECTOR PL = XMLoadFloat3(&mesh->vertex_positions[x.ind]); + switch (mode) + { + case MODE_SCULPTING_ADD: + PL += averageNormal * x.affection; + break; + case MODE_SCULPTING_SUBTRACT: + PL -= averageNormal * x.affection; + break; + } + XMStoreFloat3(&mesh->vertex_positions[x.ind], PL); + } } if (wireframe)