/
redgpu
/
ezEngine
Обзор
Документация
Войти
/
redgpu
/
ezEngine
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
dev
Code/EnginePlugins/JoltPlugin/Shapes/Implementation/JoltShapeSphereComponent.cpp
94 строки
3 KB
Jan Krassnigg
Editor usability fixes (#1433)
21 ноя 2024, 13:04
Не верифицирован
21 ноя 2024, 13:04
49bc0af
Код
Авторство
О чём код?
#include <JoltPlugin/JoltPluginPCH.h> #include <Core/Messages/UpdateLocalBoundsMessage.h> #include <Core/WorldSerializer/WorldReader.h> #include <Core/WorldSerializer/WorldWriter.h> #include <Jolt/Physics/Collision/Shape/SphereShape.h> #include <JoltPlugin/Resources/JoltMaterial.h> #include <JoltPlugin/Shapes/JoltShapeSphereComponent.h> #include <JoltPlugin/Utilities/JoltConversionUtils.h> #include <Physics/Collision/Shape/EmptyShape.h> // clang-format off EZ_BEGIN_COMPONENT_TYPE(ezJoltShapeSphereComponent, 1, ezComponentMode::Static) { EZ_BEGIN_PROPERTIES { EZ_ACCESSOR_PROPERTY("Radius", GetRadius, SetRadius)->AddAttributes(new ezDefaultValueAttribute(0.5f), new ezClampValueAttribute(0.0f, ezVariant())), } EZ_END_PROPERTIES; EZ_BEGIN_MESSAGEHANDLERS { EZ_MESSAGE_HANDLER(ezMsgUpdateLocalBounds, OnUpdateLocalBounds), } EZ_END_MESSAGEHANDLERS; EZ_BEGIN_ATTRIBUTES { new ezSphereManipulatorAttribute("Radius"), new ezSphereVisualizerAttribute("Radius"), } EZ_END_ATTRIBUTES; } EZ_END_DYNAMIC_REFLECTED_TYPE; // clang-format on ezJoltShapeSphereComponent::ezJoltShapeSphereComponent() = default; ezJoltShapeSphereComponent::~ezJoltShapeSphereComponent() = default; void ezJoltShapeSphereComponent::SerializeComponent(ezWorldWriter& inout_stream) const { SUPER::SerializeComponent(inout_stream); auto& s = inout_stream.GetStream(); s << m_fRadius; } void ezJoltShapeSphereComponent::DeserializeComponent(ezWorldReader& inout_stream) { SUPER::DeserializeComponent(inout_stream); // const ezUInt32 uiVersion = inout_stream.GetComponentTypeVersion(GetStaticRTTI()); auto& s = inout_stream.GetStream(); s >> m_fRadius; } void ezJoltShapeSphereComponent::OnUpdateLocalBounds(ezMsgUpdateLocalBounds& msg) const { msg.AddBounds(ezBoundingSphere::MakeFromCenterAndRadius(ezVec3::MakeZero(), m_fRadius), ezInvalidSpatialDataCategory); } void ezJoltShapeSphereComponent::SetRadius(float f) { m_fRadius = ezMath::Max(f, 0.0f); if (IsActiveAndInitialized()) { GetOwner()->UpdateLocalBounds(); } } void ezJoltShapeSphereComponent::CreateShapes(ezDynamicArray<ezJoltSubShape>& out_Shapes, const ezTransform& rootTransform, float fDensity, const ezJoltMaterial* pMaterial) { ezJoltSubShape& sub = out_Shapes.ExpandAndGetRef(); sub.m_Transform = ezTransform::MakeLocalTransform(rootTransform, GetOwner()->GetGlobalTransform()); if (m_fRadius > 0.0f) { auto pNewShape = new JPH::SphereShape(m_fRadius); pNewShape->SetDensity(fDensity); pNewShape->SetMaterial(pMaterial); sub.m_pShape = pNewShape; } else { sub.m_pShape = new JPH::EmptyShape(); } sub.m_pShape->AddRef(); sub.m_pShape->SetUserData(reinterpret_cast<ezUInt64>(GetUserData())); } EZ_STATICLINK_FILE(JoltPlugin, JoltPlugin_Shapes_Implementation_JoltShapeSphereComponent);