/
redgpu
/
ezEngine
Обзор
Документация
Войти
/
redgpu
/
ezEngine
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
dev
Code/Editor/EditorFramework/Visualizers/Implementation/DirectionVisualizerAdapter.cpp
92 строки
3 KB
C-Core
Water volume and VSE water shader (#1808)
04 фев 2026, 16:54
Не верифицирован
04 фев 2026, 16:54
5ad89f2
Код
Авторство
О чём код?
#include <EditorFramework/EditorFrameworkPCH.h> #include <EditorFramework/Assets/AssetDocument.h> #include <EditorFramework/Visualizers/DirectionVisualizerAdapter.h> #include <ToolsFoundation/Object/ObjectAccessorBase.h> ezDirectionVisualizerAdapter::ezDirectionVisualizerAdapter() = default; ezDirectionVisualizerAdapter::~ezDirectionVisualizerAdapter() = default; void ezDirectionVisualizerAdapter::Finalize() { auto* pDoc = m_pObject->GetDocumentObjectManager()->GetDocument()->GetMainDocument(); const ezAssetDocument* pAssetDocument = ezDynamicCast<const ezAssetDocument*>(pDoc); EZ_ASSERT_DEV(pAssetDocument != nullptr, "Visualizers are only supported in ezAssetDocument."); const ezDirectionVisualizerAttribute* pAttr = static_cast<const ezDirectionVisualizerAttribute*>(m_pVisualizerAttr); m_hGizmo.ConfigureHandle(nullptr, ezEngineGizmoHandleType::Arrow, pAttr->m_Color, ezGizmoFlags::ShowInOrtho | ezGizmoFlags::Visualizer); pAssetDocument->AddSyncObject(&m_hGizmo); m_hGizmo.SetVisible(m_bVisualizerIsVisible); } void ezDirectionVisualizerAdapter::Update() { m_hGizmo.SetVisible(m_bVisualizerIsVisible); const ezDirectionVisualizerAttribute* pAttr = static_cast<const ezDirectionVisualizerAttribute*>(m_pVisualizerAttr); if (!pAttr->GetColorProperty().IsEmpty()) { ezObjectAccessorBase* pObjectAccessor = GetObjectAccessor(); ezVariant value; pObjectAccessor->GetValue(m_pObject, GetProperty(pAttr->GetColorProperty()), value).AssertSuccess(); EZ_ASSERT_DEBUG(value.IsValid() && value.CanConvertTo<ezColor>(), "Invalid property bound to ezDirectionVisualizerAttribute 'color'"); m_hGizmo.SetColor(value.ConvertTo<ezColor>() * pAttr->m_Color); } } void ezDirectionVisualizerAdapter::UpdateGizmoTransform() { const ezDirectionVisualizerAttribute* pAttr = static_cast<const ezDirectionVisualizerAttribute*>(m_pVisualizerAttr); float fScale = pAttr->m_fScale; if (!pAttr->GetLengthProperty().IsEmpty()) { ezObjectAccessorBase* pObjectAccessor = GetObjectAccessor(); ezVariant value; pObjectAccessor->GetValue(m_pObject, GetProperty(pAttr->GetLengthProperty()), value).AssertSuccess(); EZ_ASSERT_DEBUG(value.IsValid() && value.CanConvertTo<float>(), "Invalid property bound to ezDirectionVisualizerAttribute 'length'"); fScale *= value.ConvertTo<float>(); } ezVec3 axis = ezBasisAxis::GetBasisVector(pAttr->m_Axis); if (!pAttr->GetAxisProperty().IsEmpty()) { ezObjectAccessorBase* pObjectAccessor = GetObjectAccessor(); ezVariant value; pObjectAccessor->GetValue(m_pObject, GetProperty(pAttr->GetAxisProperty()), value).AssertSuccess(); if (value.IsA<ezVec3>()) { axis = value.ConvertTo<ezVec3>(); fScale *= axis.GetLength(); axis.NormalizeIfNotZero(ezVec3::MakeAxisX()).IgnoreResult(); } else { EZ_ASSERT_DEBUG(value.IsValid() && value.CanConvertTo<ezInt32>(), "Invalid property bound to ezDirectionVisualizerAttribute 'length'"); axis = ezBasisAxis::GetBasisVector(static_cast<ezBasisAxis::Enum>(value.ConvertTo<ezInt32>())); } } const ezQuat axisRotation = ezQuat::MakeShortestRotation(ezVec3::MakeAxisX(), axis); ezTransform t; t.m_qRotation = axisRotation; t.m_vScale = ezVec3(fScale); t.m_vPosition = axisRotation * ezVec3(fScale * 0.5f, 0, 0); ezTransform tObject = GetObjectTransform(); tObject.m_vScale.Set(1.0f); m_hGizmo.SetTransformation(tObject * t); }