Skip to content

Commit

Permalink
editor: translator snap to surface improvement; subset order modifica…
Browse files Browse the repository at this point in the history
…tion button;
  • Loading branch information
turanszkij committed Jan 20, 2025
1 parent fd26919 commit 03958b5
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 5 deletions.
42 changes: 42 additions & 0 deletions Editor/MeshWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,47 @@ void MeshWindow::Create(EditorComponent* _editor)
});
AddWidget(&subsetRemoveButton);

subsetLastButton.Create("Move subset to last index");
subsetLastButton.SetTooltip("Move subset to the last index to render last. Useful if you want to force transparency render order within subsets.");
subsetLastButton.OnClick([=](wi::gui::EventArgs args) {
Scene& scene = editor->GetCurrentScene();
MeshComponent* mesh = scene.meshes.GetComponent(entity);
if (mesh != nullptr)
{
wi::Archive& archive = editor->AdvanceHistory();
archive << EditorComponent::HISTORYOP_COMPONENT_DATA;
editor->RecordEntity(archive, entity);

int selected = subsetComboBox.GetSelected();

uint32_t lod_count = mesh->GetLODCount();
wi::vector<MeshComponent::MeshSubset> newSubsets;
newSubsets.reserve(mesh->subsets.size());

for (uint32_t lod = 0; lod < lod_count; ++lod)
{
uint32_t first_subset = 0;
uint32_t last_subset = 0;
mesh->GetLODSubsetRange(lod, first_subset, last_subset);
int s = 0;
for (uint32_t i = first_subset; i < last_subset; ++i)
{
if (s != selected)
{
newSubsets.push_back(mesh->subsets[i]);
}
s++;
}
newSubsets.push_back(mesh->subsets[first_subset + selected]);
}
mesh->subsets = newSubsets;
SetEntity(entity, mesh->subsets_per_lod > 0 ? ((int)mesh->subsets_per_lod - 1) : (int)mesh->subsets.size());

editor->RecordEntity(archive, entity);
}
});
AddWidget(&subsetLastButton);

doubleSidedCheckBox.Create("Double Sided: ");
doubleSidedCheckBox.SetTooltip("If enabled, the inside of the mesh will be visible.");
doubleSidedCheckBox.SetSize(XMFLOAT2(hei, hei));
Expand Down Expand Up @@ -1178,6 +1219,7 @@ void MeshWindow::ResizeLayout()
subsetRemoveButton.SetPos(XMFLOAT2(subsetComboBox.GetPos().x + subsetComboBox.GetSize().x + 1 + subsetComboBox.GetSize().y, subsetComboBox.GetPos().y));
subsetRemoveButton.SetSize(XMFLOAT2(subsetComboBox.GetSize().y, subsetComboBox.GetSize().y));
add(subsetMaterialComboBox);
add(subsetLastButton);
add_right(doubleSidedCheckBox);
add_right(doubleSidedShadowCheckBox);
add_right(bvhCheckBox);
Expand Down
1 change: 1 addition & 0 deletions Editor/MeshWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class MeshWindow : public wi::gui::Window

wi::gui::Label meshInfoLabel;
wi::gui::Button subsetRemoveButton;
wi::gui::Button subsetLastButton;
wi::gui::ComboBox subsetComboBox;
wi::gui::ComboBox subsetMaterialComboBox;
wi::gui::CheckBox doubleSidedCheckBox;
Expand Down
34 changes: 29 additions & 5 deletions Editor/Translator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,23 +472,47 @@ void Translator::Update(const CameraComponent& camera, const XMFLOAT4& currentMo
if (wi::input::Down(wi::input::BUTTON::KEYBOARD_BUTTON_LSHIFT) || wi::input::Down(wi::input::BUTTON::KEYBOARD_BUTTON_RSHIFT))
{
// Snap to surface mode:
temp_filters.reserve(selected.size());
for (auto& x : selected)

// 1.) Collect all objects which could be in the hierarchy of any of the selected ones
// This is important because we could select a top parent that doesn't have object
// but I still want to disable children's filters
selectedWithHierarchy.clear();
for (size_t i = 0; i < scene.objects.GetCount(); ++i)
{
Entity entity = scene.objects.GetEntity(i);
for (auto& potential_parent : selectedEntitiesNonRecursive)
{
if (entity == potential_parent || scene.Entity_IsDescendant(entity, potential_parent))
{
selectedWithHierarchy.push_back(entity);
break;
}
}
}

// 2.) Disable all object filters which are part of selection hierarchy for the next picking
// This is to filter them out from picking, we only want to pick what's underneath
temp_filters.reserve(selectedWithHierarchy.size());
for (auto& entity : selectedWithHierarchy)
{
ObjectComponent* object = scene.objects.GetComponent(x.entity);
ObjectComponent* object = scene.objects.GetComponent(entity);
if (object == nullptr)
continue;
temp_filters.push_back(uint64_t(object->filterMask) | (uint64_t(object->filterMaskDynamic) << 32ull));
object->filterMask = 0;
object->filterMaskDynamic = 0;
}

// 3.) Pick into scene to determine placement position
Ray ray = wi::renderer::GetPickRay((long)currentMouse.x, (long)currentMouse.y, canvas, camera);
wi::scene::Scene::RayIntersectionResult result = scene.Intersects(ray, wi::enums::FILTER_OBJECT_ALL);
transform.translation_local = result.position;

// 4.) Restore all filters to original values
size_t ind = 0;
for (auto& x : selected)
for (auto& entity : selectedWithHierarchy)
{
ObjectComponent* object = scene.objects.GetComponent(x.entity);
ObjectComponent* object = scene.objects.GetComponent(entity);
if (object == nullptr)
continue;
uint64_t tmp = temp_filters[ind++];
Expand Down
1 change: 1 addition & 0 deletions Editor/Translator.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class Translator
float angle_start = 0;
bool has_selected_transform = false;
wi::vector<uint64_t> temp_filters;
wi::vector<wi::ecs::Entity> selectedWithHierarchy; // all the selected entities and their descendants
public:

void Update(const wi::scene::CameraComponent& camera, const XMFLOAT4& currentMouse, const wi::Canvas& canvas);
Expand Down

0 comments on commit 03958b5

Please sign in to comment.