editor: snap to surface transform
This commit is contained in:
+2
-1
@@ -884,7 +884,8 @@ void EditorComponent::Load()
|
||||
ss += "Select: Left mouse button\n";
|
||||
ss += "Interact with physics/water/grass: Middle mouse button\n";
|
||||
ss += "Faster camera: Left Shift button or controller R2/RT\n";
|
||||
ss += "Snap transform: Left Ctrl (hold while transforming)\n";
|
||||
ss += "Snap to grid transform: Ctrl (hold while transforming)\n";
|
||||
ss += "Snap to surface transform: Shift (hold while transforming)\n";
|
||||
ss += "Camera up: E\n";
|
||||
ss += "Camera down: Q\n";
|
||||
ss += "Duplicate entity: Ctrl + D\n";
|
||||
|
||||
+26
-2
@@ -453,9 +453,9 @@ void Translator::Update(const CameraComponent& camera, const XMFLOAT4& currentMo
|
||||
transform.Scale(scale);
|
||||
}
|
||||
|
||||
if (wi::input::Down(wi::input::BUTTON::KEYBOARD_BUTTON_LCONTROL))
|
||||
if (wi::input::Down(wi::input::BUTTON::KEYBOARD_BUTTON_LCONTROL) || wi::input::Down(wi::input::BUTTON::KEYBOARD_BUTTON_RCONTROL))
|
||||
{
|
||||
// Snap mode:
|
||||
// Snap to grid mode:
|
||||
if (isTranslator)
|
||||
{
|
||||
transform.translation_local.x = std::round(transform.translation_local.x / translate_snap) * translate_snap;
|
||||
@@ -469,6 +469,30 @@ void Translator::Update(const CameraComponent& camera, const XMFLOAT4& currentMo
|
||||
transform.scale_local.z = std::max(scale_snap, std::round(transform.scale_local.z / scale_snap) * scale_snap);
|
||||
}
|
||||
}
|
||||
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)
|
||||
{
|
||||
ObjectComponent* object = scene.objects.GetComponent(x.entity);
|
||||
if (object == nullptr)
|
||||
continue;
|
||||
temp_filters.push_back(object->filterMask);
|
||||
object->filterMask = 0;
|
||||
}
|
||||
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;
|
||||
size_t ind = 0;
|
||||
for (auto& x : selected)
|
||||
{
|
||||
ObjectComponent* object = scene.objects.GetComponent(x.entity);
|
||||
if (object == nullptr)
|
||||
continue;
|
||||
object->filterMask = temp_filters[ind++];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
transform.UpdateTransform();
|
||||
|
||||
@@ -11,6 +11,7 @@ private:
|
||||
float angle = 0;
|
||||
float angle_start = 0;
|
||||
bool has_selected_transform = false;
|
||||
wi::vector<uint32_t> temp_filters;
|
||||
public:
|
||||
|
||||
void Update(const wi::scene::CameraComponent& camera, const XMFLOAT4& currentMouse, const wi::Canvas& canvas);
|
||||
|
||||
@@ -5333,7 +5333,7 @@ namespace wi::scene
|
||||
|
||||
return result;
|
||||
}
|
||||
bool Scene::IntersectsFirst(const wi::primitive::Ray& ray, uint32_t filterMask, uint32_t layerMask, uint32_t lod) const
|
||||
bool Scene::IntersectsFirst(const Ray& ray, uint32_t filterMask, uint32_t layerMask, uint32_t lod) const
|
||||
{
|
||||
bool result = false;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user