From 2a86f71cd6db2cea9cbba28e3a3100680e310630 Mon Sep 17 00:00:00 2001 From: Turanszki Janos Date: Sat, 2 May 2020 12:26:37 +0100 Subject: [PATCH] input fix and editor improvements --- Editor/AnimationWindow.cpp | 5 +- Editor/Editor.cpp | 18 +----- Editor/EmitterWindow.cpp | 4 +- Editor/IKWindow.cpp | 8 +-- Editor/MaterialWindow.cpp | 28 +++------ Editor/ObjectWindow.cpp | 13 +--- Editor/TransformWindow.cpp | 8 +-- Editor/Translator.cpp | 118 ++++++++++++++++++++++--------------- WickedEngine/wiInput.cpp | 2 +- WickedEngine/wiVersion.cpp | 2 +- 10 files changed, 86 insertions(+), 120 deletions(-) diff --git a/Editor/AnimationWindow.cpp b/Editor/AnimationWindow.cpp index 2fd3ab33e..4a8af4bc9 100644 --- a/Editor/AnimationWindow.cpp +++ b/Editor/AnimationWindow.cpp @@ -143,10 +143,7 @@ void AnimationWindow::Update() { Entity e = scene.animations.GetEntity(i); NameComponent& name = *scene.names.GetComponent(e); - - std::stringstream ss(""); - ss << name.name << " (" << e << ")"; - animationsComboBox->AddItem(ss.str()); + animationsComboBox->AddItem(name.name.empty() ? std::to_string(e) : name.name); if (e == entity) { diff --git a/Editor/Editor.cpp b/Editor/Editor.cpp index 82a277ec5..42f905964 100644 --- a/Editor/Editor.cpp +++ b/Editor/Editor.cpp @@ -891,12 +891,8 @@ void EditorComponent::PushToSceneGraphView(wiECS::Entity entity, int level) item.userdata = entity; item.selected = IsSelected(entity); item.open = scenegraphview_closed_items.count(entity) == 0; - item.name = "(" + std::to_string(entity) + ")"; const NameComponent* name = scene.names.GetComponent(entity); - if (name != nullptr) - { - item.name = name->name + " " + item.name; - } + item.name = name == nullptr ? std::to_string(entity) : name->name; sceneGraphView->AddItem(item); scenegraphview_added_items.insert(entity); @@ -961,12 +957,8 @@ void EditorComponent::Update(float dt) item.userdata = entity; item.selected = IsSelected(entity); item.open = scenegraphview_closed_items.count(entity) == 0; - item.name = "(" + std::to_string(entity) + ")"; const NameComponent* name = scene.names.GetComponent(entity); - if (name != nullptr) - { - item.name = name->name + " " + item.name; - } + item.name = name == nullptr ? std::to_string(entity) : name->name; sceneGraphView->AddItem(item); scenegraphview_added_items.insert(entity); @@ -985,12 +977,8 @@ void EditorComponent::Update(float dt) item.userdata = entity; item.selected = IsSelected(entity); item.open = scenegraphview_closed_items.count(entity) == 0; - item.name = "(" + std::to_string(entity) + ")"; const NameComponent* name = scene.names.GetComponent(entity); - if (name != nullptr) - { - item.name = name->name + " " + item.name; - } + item.name = name == nullptr ? std::to_string(entity) : name->name; sceneGraphView->AddItem(item); scenegraphview_added_items.insert(entity); diff --git a/Editor/EmitterWindow.cpp b/Editor/EmitterWindow.cpp index 440bb23a6..e0d7024d6 100644 --- a/Editor/EmitterWindow.cpp +++ b/Editor/EmitterWindow.cpp @@ -609,7 +609,5 @@ void EmitterWindow::UpdateData() infoLabel->SetText(ss.str()); - ss.str(""); - ss << name->name << " (" << entity << ")"; - emitterNameField->SetText(ss.str()); + emitterNameField->SetText(name->name); } diff --git a/Editor/IKWindow.cpp b/Editor/IKWindow.cpp index c7c029e56..91770e793 100644 --- a/Editor/IKWindow.cpp +++ b/Editor/IKWindow.cpp @@ -109,14 +109,8 @@ void IKWindow::SetEntity(Entity entity) for (size_t i = 0; i < scene.transforms.GetCount(); ++i) { Entity entity = scene.transforms.GetEntity(i); - std::string str; const NameComponent* name = scene.names.GetComponent(entity); - if (name != nullptr) - { - str = name->name; - } - str = str + " (" + std::to_string(entity) + ")"; - targetCombo->AddItem(str); + targetCombo->AddItem(name == nullptr ? std::to_string(entity) : name->name); if (ik->target == entity) { diff --git a/Editor/MaterialWindow.cpp b/Editor/MaterialWindow.cpp index 72cce0bf8..bb6023947 100644 --- a/Editor/MaterialWindow.cpp +++ b/Editor/MaterialWindow.cpp @@ -788,10 +788,8 @@ void MaterialWindow::SetEntity(Entity entity) if (material != nullptr) { const NameComponent& name = *scene.names.GetComponent(entity); - stringstream ss(""); - ss << name.name << " (" << entity << ")"; - materialNameField->SetValue(ss.str()); + materialNameField->SetValue(name.name); waterCheckBox->SetCheck(material->IsWater()); planarReflCheckBox->SetCheck(material->HasPlanarReflection()); shadowCasterCheckBox->SetCheck(material->IsCastingShadow()); @@ -831,24 +829,12 @@ void MaterialWindow::SetEntity(Entity entity) texture_emissive_Button->SetText(wiHelper::GetFileNameFromPath(material->emissiveMapName)); texture_occlusion_Button->SetText(wiHelper::GetFileNameFromPath(material->occlusionMapName)); - ss.str(""); - ss << material->uvset_baseColorMap; - texture_baseColor_uvset_Field->SetText(ss.str()); - ss.str(""); - ss << material->uvset_normalMap; - texture_normal_uvset_Field->SetText(ss.str()); - ss.str(""); - ss << material->uvset_surfaceMap; - texture_surface_uvset_Field->SetText(ss.str()); - ss.str(""); - ss << material->uvset_displacementMap; - texture_displacement_uvset_Field->SetText(ss.str()); - ss.str(""); - ss << material->uvset_emissiveMap; - texture_emissive_uvset_Field->SetText(ss.str()); - ss.str(""); - ss << material->uvset_occlusionMap; - texture_occlusion_uvset_Field->SetText(ss.str()); + texture_baseColor_uvset_Field->SetText(std::to_string(material->uvset_baseColorMap)); + texture_normal_uvset_Field->SetText(std::to_string(material->uvset_normalMap)); + texture_surface_uvset_Field->SetText(std::to_string(material->uvset_surfaceMap)); + texture_displacement_uvset_Field->SetText(std::to_string(material->uvset_displacementMap)); + texture_emissive_uvset_Field->SetText(std::to_string(material->uvset_emissiveMap)); + texture_occlusion_uvset_Field->SetText(std::to_string(material->uvset_occlusionMap)); } else { diff --git a/Editor/ObjectWindow.cpp b/Editor/ObjectWindow.cpp index 087f60888..8842fecae 100644 --- a/Editor/ObjectWindow.cpp +++ b/Editor/ObjectWindow.cpp @@ -600,18 +600,7 @@ void ObjectWindow::SetEntity(Entity entity) objectWindow->SetEnabled(true); const NameComponent* name = scene.names.GetComponent(entity); - if (name != nullptr) - { - std::stringstream ss(""); - ss << name->name << " (" << entity << ")"; - nameLabel->SetText(ss.str()); - } - else - { - std::stringstream ss(""); - ss<< "(" << entity << ")"; - nameLabel->SetText(ss.str()); - } + nameLabel->SetText(name == nullptr ? std::to_string(entity) : name->name); renderableCheckBox->SetCheck(object->IsRenderable()); cascadeMaskSlider->SetValue((float)object->cascadeMask); diff --git a/Editor/TransformWindow.cpp b/Editor/TransformWindow.cpp index af773b737..72546f536 100644 --- a/Editor/TransformWindow.cpp +++ b/Editor/TransformWindow.cpp @@ -255,14 +255,8 @@ void TransformWindow::SetEntity(Entity entity) for (size_t i = 0; i < scene.transforms.GetCount(); ++i) { Entity entity = scene.transforms.GetEntity(i); - std::string str; const NameComponent* name = scene.names.GetComponent(entity); - if (name != nullptr) - { - str = name->name; - } - str = str + " (" + std::to_string(entity) + ")"; - parentCombo->AddItem(str); + parentCombo->AddItem(name == nullptr ? std::to_string(entity) : name->name); if (hier != nullptr && hier->parentID == entity) { diff --git a/Editor/Translator.cpp b/Editor/Translator.cpp index ac0c67b22..e21810c64 100644 --- a/Editor/Translator.cpp +++ b/Editor/Translator.cpp @@ -17,6 +17,7 @@ GPUBuffer vertexBuffer_Origin; UINT vertexCount_Axis = 0; UINT vertexCount_Plane = 0; UINT vertexCount_Origin = 0; +float origin_size = 0.2f; void Translator::LoadShaders() { @@ -106,7 +107,7 @@ Translator::Translator() if (!vertexBuffer_Origin.IsValid()) { { - float edge = 0.2f; + float edge = origin_size; XMFLOAT4 verts[] = { XMFLOAT4(-edge,edge,edge,1), XMFLOAT4(1,1,1,1), XMFLOAT4(-edge,-edge,edge,1), XMFLOAT4(1,1,1,1), @@ -183,67 +184,56 @@ void Translator::Update() XMMATRIX P = cam.GetProjection(); XMMATRIX V = cam.GetView(); XMMATRIX W = XMMatrixIdentity(); + XMFLOAT3 p = transform.GetPosition(); - dist = wiMath::Distance(transform.GetPosition(), cam.Eye) * 0.05f; + dist = wiMath::Distance(p, cam.Eye) * 0.05f; - XMVECTOR o, x, y, z, p, xy, xz, yz; + RAY ray = wiRenderer::GetPickRay((long)pointer.x, (long)pointer.y); - o = pos; - x = o + XMVectorSet(3, 0, 0, 0) * dist; - y = o + XMVectorSet(0, 3, 0, 0) * dist; - z = o + XMVectorSet(0, 0, 3, 0) * dist; - p = XMLoadFloat4(&pointer); - xy = o + XMVectorSet(0.5f, 0.5f, 0, 0) * dist; - xz = o + XMVectorSet(0.5f, 0, 0.5f, 0) * dist; - yz = o + XMVectorSet(0, 0.5f, 0.5f, 0) * dist; + XMVECTOR x, y, z, xy, xz, yz; + x = pos + XMVectorSet(3, 0, 0, 0) * dist; + y = pos + XMVectorSet(0, 3, 0, 0) * dist; + z = pos + XMVectorSet(0, 0, 3, 0) * dist; + xy = pos + XMVectorSet(1, 1, 0, 0) * dist; + xz = pos + XMVectorSet(1, 0, 1, 0) * dist; + yz = pos + XMVectorSet(0, 1, 1, 0) * dist; - o = XMVector3Project(o, 0, 0, cam.width, cam.height, 0, 1, P, V, W); - x = XMVector3Project(x, 0, 0, cam.width, cam.height, 0, 1, P, V, W); - y = XMVector3Project(y, 0, 0, cam.width, cam.height, 0, 1, P, V, W); - z = XMVector3Project(z, 0, 0, cam.width, cam.height, 0, 1, P, V, W); - xy = XMVector3Project(xy, 0, 0, cam.width, cam.height, 0, 1, P, V, W); - xz = XMVector3Project(xz, 0, 0, cam.width, cam.height, 0, 1, P, V, W); - yz = XMVector3Project(yz, 0, 0, cam.width, cam.height, 0, 1, P, V, W); + AABB aabb_origin; + aabb_origin.createFromHalfWidth(p, XMFLOAT3(origin_size * dist, origin_size * dist, origin_size * dist)); - XMVECTOR oDisV = XMVector3Length(o - p); - XMVECTOR xyDisV = XMVector3Length(xy - p); - XMVECTOR xzDisV = XMVector3Length(xz - p); - XMVECTOR yzDisV = XMVector3Length(yz - p); + XMFLOAT3 maxp; + XMStoreFloat3(&maxp, x); + AABB aabb_x = AABB::Merge(AABB(p, maxp), aabb_origin); - float xDis = wiMath::GetPointSegmentDistance(p, o, x); - float yDis = wiMath::GetPointSegmentDistance(p, o, y); - float zDis = wiMath::GetPointSegmentDistance(p, o, z); - float oDis = XMVectorGetX(oDisV); - float xyDis = XMVectorGetX(xyDisV); - float xzDis = XMVectorGetX(xzDisV); - float yzDis = XMVectorGetX(yzDisV); + XMStoreFloat3(&maxp, y); + AABB aabb_y = AABB::Merge(AABB(p, maxp), aabb_origin); - if (oDis < 10) + XMStoreFloat3(&maxp, z); + AABB aabb_z = AABB::Merge(AABB(p, maxp), aabb_origin); + + XMStoreFloat3(&maxp, xy); + AABB aabb_xy = AABB(p, maxp); + + XMStoreFloat3(&maxp, xz); + AABB aabb_xz = AABB(p, maxp); + + XMStoreFloat3(&maxp, yz); + AABB aabb_yz = AABB(p, maxp); + + if (aabb_origin.intersects(ray)) { state = TRANSLATOR_XYZ; } - else if (xyDis < 20) - { - state = TRANSLATOR_XY; - } - else if (xzDis < 20) - { - state = TRANSLATOR_XZ; - } - else if (yzDis < 20) - { - state = TRANSLATOR_YZ; - } - else if (xDis < 10) + else if (aabb_x.intersects(ray)) { state = TRANSLATOR_X; } - else if (yDis < 10) + else if (aabb_y.intersects(ray)) { state = TRANSLATOR_Y; } - else if (zDis < 10) + else if (aabb_z.intersects(ray)) { state = TRANSLATOR_Z; } @@ -251,9 +241,39 @@ void Translator::Update() { state = TRANSLATOR_IDLE; } + + if (state != TRANSLATOR_XYZ) + { + // these can overlap, so take closest one (by checking plane ray trace distance): + XMVECTOR origin = XMLoadFloat3(&ray.origin); + XMVECTOR direction = XMLoadFloat3(&ray.direction); + XMVECTOR N = XMVectorSet(0, 0, 1, 0); + + float prio = FLT_MAX; + if (aabb_xy.intersects(ray)) + { + state = TRANSLATOR_XY; + prio = XMVectorGetX(XMVector3Dot(N, (origin - pos) / XMVectorAbs(XMVector3Dot(N, direction)))); + } + + N = XMVectorSet(0, 1, 0, 0); + float d = XMVectorGetX(XMVector3Dot(N, (origin - pos) / XMVectorAbs(XMVector3Dot(N, direction)))); + if (d < prio && aabb_xz.intersects(ray)) + { + state = TRANSLATOR_XZ; + prio = d; + } + + N = XMVectorSet(1, 0, 0, 0); + d = XMVectorGetX(XMVector3Dot(N, (origin - pos) / XMVectorAbs(XMVector3Dot(N, direction)))); + if (d < prio && aabb_yz.intersects(ray)) + { + state = TRANSLATOR_YZ; + } + } } - if (dragging || (state != TRANSLATOR_IDLE && wiInput::Down(wiInput::MOUSE_BUTTON_LEFT))) + if (dragging || (state != TRANSLATOR_IDLE && wiInput::Press(wiInput::MOUSE_BUTTON_LEFT))) { if (!dragging) { @@ -441,7 +461,7 @@ void Translator::Draw(const CameraComponent& camera, CommandList cmd) const // xy XMStoreFloat4x4(&sb.g_xTransform, matX); - sb.g_xColor = state == TRANSLATOR_XY ? XMFLOAT4(1, 1, 1, 1) : XMFLOAT4(0.2f, 0.2f, 0, 0.2f); + sb.g_xColor = state == TRANSLATOR_XY ? XMFLOAT4(1, 1, 1, 1) : XMFLOAT4(0.4f, 0.4f, 0, 0.4f); device->UpdateBuffer(wiRenderer::GetConstantBuffer(CBTYPE_MISC), &sb, cmd); device->BindConstantBuffer(VS, wiRenderer::GetConstantBuffer(CBTYPE_MISC), CB_GETBINDSLOT(MiscCB), cmd); device->BindConstantBuffer(PS, wiRenderer::GetConstantBuffer(CBTYPE_MISC), CB_GETBINDSLOT(MiscCB), cmd); @@ -449,7 +469,7 @@ void Translator::Draw(const CameraComponent& camera, CommandList cmd) const // xz XMStoreFloat4x4(&sb.g_xTransform, matZ); - sb.g_xColor = state == TRANSLATOR_XZ ? XMFLOAT4(1, 1, 1, 1) : XMFLOAT4(0.2f, 0.2f, 0, 0.2f); + sb.g_xColor = state == TRANSLATOR_XZ ? XMFLOAT4(1, 1, 1, 1) : XMFLOAT4(0.4f, 0.4f, 0, 0.4f); device->UpdateBuffer(wiRenderer::GetConstantBuffer(CBTYPE_MISC), &sb, cmd); device->BindConstantBuffer(VS, wiRenderer::GetConstantBuffer(CBTYPE_MISC), CB_GETBINDSLOT(MiscCB), cmd); device->BindConstantBuffer(PS, wiRenderer::GetConstantBuffer(CBTYPE_MISC), CB_GETBINDSLOT(MiscCB), cmd); @@ -457,7 +477,7 @@ void Translator::Draw(const CameraComponent& camera, CommandList cmd) const // yz XMStoreFloat4x4(&sb.g_xTransform, matY); - sb.g_xColor = state == TRANSLATOR_YZ ? XMFLOAT4(1, 1, 1, 1) : XMFLOAT4(0.2f, 0.2f, 0, 0.2f); + sb.g_xColor = state == TRANSLATOR_YZ ? XMFLOAT4(1, 1, 1, 1) : XMFLOAT4(0.4f, 0.4f, 0, 0.4f); device->UpdateBuffer(wiRenderer::GetConstantBuffer(CBTYPE_MISC), &sb, cmd); device->BindConstantBuffer(VS, wiRenderer::GetConstantBuffer(CBTYPE_MISC), CB_GETBINDSLOT(MiscCB), cmd); device->BindConstantBuffer(PS, wiRenderer::GetConstantBuffer(CBTYPE_MISC), CB_GETBINDSLOT(MiscCB), cmd); diff --git a/WickedEngine/wiInput.cpp b/WickedEngine/wiInput.cpp index bdb0bfb80..64a416863 100644 --- a/WickedEngine/wiInput.cpp +++ b/WickedEngine/wiInput.cpp @@ -358,7 +358,7 @@ namespace wiInput inputs.insert(make_pair(input, 0)); return true; } - if (iter->second <= 0) + if (iter->second == 1) { return true; } diff --git a/WickedEngine/wiVersion.cpp b/WickedEngine/wiVersion.cpp index 94d8cd530..988d8116c 100644 --- a/WickedEngine/wiVersion.cpp +++ b/WickedEngine/wiVersion.cpp @@ -9,7 +9,7 @@ namespace wiVersion // minor features, major updates const int minor = 40; // minor bug fixes, alterations, refactors, updates - const int revision = 6; + const int revision = 7; const std::string version_string = std::to_string(major) + "." + std::to_string(minor) + "." + std::to_string(revision);