Skip to content
1,272 changes: 1,174 additions & 98 deletions Mods/Editor/Src/Components/DebugChannels.cpp

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions Mods/Editor/Src/Components/EntityTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1167,8 +1167,8 @@ void Editor::DestroyEntityInternal(ZEntityRef p_Entity, std::optional<std::strin
m_SelectedEntity = {};
}

if (m_SelectedGizmoEntity == p_Entity) {
m_SelectedGizmoEntity = {};
if (m_SelectedDebugEntity == p_Entity) {
m_SelectedDebugEntity = {};
}

// Remove from the tree.
Expand Down Expand Up @@ -1198,8 +1198,8 @@ void Editor::DestroyEntityInternal(ZEntityRef p_Entity, std::optional<std::strin
m_SelectedEntity = {};
}

if (m_SelectedGizmoEntity == s_CurrentChild->Entity) {
m_SelectedGizmoEntity = {};
if (m_SelectedDebugEntity == s_CurrentChild->Entity) {
m_SelectedDebugEntity = {};
}

for (auto& s_Child : s_ChildrenQueue.front()->Children) {
Expand Down Expand Up @@ -1253,8 +1253,8 @@ void Editor::DestroyEntityNodeInternal(
m_SelectedEntity = {};
}

if (m_SelectedGizmoEntity == p_NodeToRemove->Entity) {
m_SelectedGizmoEntity = {};
if (m_SelectedDebugEntity == p_NodeToRemove->Entity) {
m_SelectedDebugEntity = {};
}
}

Expand All @@ -1276,8 +1276,8 @@ void Editor::DestroyEntityNodeInternal(
m_SelectedEntity = {};
}

if (m_SelectedGizmoEntity == s_CurrentChild->Entity) {
m_SelectedGizmoEntity = {};
if (m_SelectedDebugEntity == s_CurrentChild->Entity) {
m_SelectedDebugEntity = {};
}

for (auto& s_Child : s_CurrentChild->Children) {
Expand Down Expand Up @@ -1354,8 +1354,8 @@ DEFINE_PLUGIN_DETOUR(
m_SelectedEntity = nullptr;
}

if (m_SelectedGizmoEntity == entityRef) {
m_SelectedGizmoEntity = nullptr;
if (m_SelectedDebugEntity == entityRef) {
m_SelectedDebugEntity = nullptr;
}

std::shared_ptr<EntityTreeNode> s_NodeToRemove;
Expand Down
4 changes: 2 additions & 2 deletions Mods/Editor/Src/Editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@ void Editor::OnMouseDown(SVector2 p_Pos, bool p_FirstClick) {
SVector3 s_Direction;
SDK()->ScreenToWorld(p_Pos, s_World, s_Direction);

if (m_DrawGizmos && RayCastGizmos(s_World, s_Direction)) {
if (RayCastDebugEntities(s_World, s_Direction)) {
return;
}

Expand Down Expand Up @@ -1361,7 +1361,7 @@ DEFINE_PLUGIN_DETOUR(Editor, void, OnClearScene, ZEntitySceneContext* th, bool p

m_SelectedAction = nullptr;

m_SelectedGizmoEntity = nullptr;
m_SelectedDebugEntity = nullptr;

{
std::scoped_lock s_Lock(m_DebugEntitiesMutex);
Expand Down
107 changes: 105 additions & 2 deletions Mods/Editor/Src/Editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@
#include <map>
#include <shared_mutex>

#include <SimpleMath.h>

#include "IPluginInterface.h"
#include "Glacier/ZEntity.h"
#include "Glacier/ZInput.h"
#include "Glacier/ZFreeCamera.h"
#include "Glacier/EDebugChannel.h"
#include "Glacier/ZCurve.h"
#include "Glacier/ZAction.h"
#include "Glacier/ZSound.h"
#include "Glacier/ZSequence.h"

#include "ImGuizmo.h"
#include "EditorServer.h"
Expand Down Expand Up @@ -98,6 +102,13 @@ class Editor : public IPluginInterface {
SMatrix m_Transform;
};

struct RayCastResult {
ZEntityRef m_Entity;
std::string m_TypeName;
EDebugChannel m_DebugChannel;
float m_Distance = FLT_MAX;
};

struct PinInfo {
std::string name;
std::string description;
Expand Down Expand Up @@ -328,6 +339,8 @@ class Editor : public IPluginInterface {
void DrawDebugEntities(IRenderer* p_Renderer);
void DrawGizmo(GizmoEntity& p_GizmoEntity, IRenderer* p_Renderer);
void DrawShapes(const DebugEntity& p_DebugEntity, IRenderer* p_Renderer);
void DrawShapes(ZSoundGateEntity* p_SoundGateEntity, IRenderer* p_Renderer);
void DrawShapes(ZSequenceEntity* p_SequenceEntity, IRenderer* p_Renderer);
void GetDebugEntities(const std::shared_ptr<EntityTreeNode>& p_EntityTreeNode);
void AddDebugEntity(
const ZEntityRef p_EntityRef,
Expand All @@ -353,7 +366,93 @@ class Editor : public IPluginInterface {
void DeleteDebugEntities(const std::shared_ptr<EntityTreeNode>& p_RootNode);
EDebugChannel ConvertDrawLayerToDebugChannel(const ZDebugGizmoEntity_EDrawLayer p_DrawLayer);
static bool EntityIDMatches(void* p_Interface, const uint64 p_EntityID);
bool RayCastGizmos(const SVector3& p_WorldPosition, const SVector3& p_Direction);

bool RayCastDebugEntities(const SVector3& p_WorldPosition, const SVector3& p_Direction);
void RayCastGizmos(const SVector3& p_WorldPosition, const SVector3& p_Direction, RayCastResult& p_Result);
void RayCastShapes(const SVector3& p_WorldPosition, const SVector3& p_Direction, RayCastResult& p_Result);

bool RayCastShape(
const DirectX::SimpleMath::Ray& p_Ray,
ZSoundGateEntity* p_SoundGateEntity,
float& p_Distance
);
bool RayCastShape(
const DirectX::SimpleMath::Ray& p_Ray,
ZSequenceEntity* p_SequenceEntity,
float& p_Distance
);

bool RayCastTrajectoryTrack(
const DirectX::SimpleMath::Ray& p_Ray,
ZTrajectoryTrackBase* p_Track,
ZEntityRef p_TargetEntity,
float& p_Distance
);
template <typename TItem, typename EvaluateFn>
bool RayCastTrajectoryItem(
const DirectX::SimpleMath::Ray& p_Ray,
TItem* p_Item,
ZTrajectoryTrackBase* p_Track,
ZEntityRef p_TargetEntity,
float& p_Distance,
EvaluateFn&& p_EvaluateFn
);

bool RayIntersectsTrajectorySegment(
const DirectX::SimpleMath::Ray& p_Ray,
const SVector3& p_Start,
const SVector3& p_End,
float p_Radius,
float& p_Distance
);
bool RayIntersectsBox(
const DirectX::SimpleMath::Ray& p_Ray,
const SMatrix& p_Transform,
const SVector3& p_Center,
const SVector3& p_Extents,
float& p_Distance
);
bool RayIntersectsSphere(
const DirectX::SimpleMath::Ray& p_Ray,
const SVector3& p_Position,
float p_Radius,
float& p_Distance
);

void DrawTrajectoryTrack(
IRenderer* p_Renderer,
ZTrajectoryTrackBase* p_Track,
const SVector4& p_Color,
ZEntityRef p_TargetEntity
);
template <typename TItem, typename EvaluateFn>
void DrawTrajectoryItem(
IRenderer* p_Renderer,
TItem* p_Item,
ZTrajectoryTrackBase* p_Track,
const SVector4& p_Color,
ZEntityRef p_TargetEntity,
EvaluateFn&& p_EvaluateFn
);
static SVector3 EvaluateTrajectoryWorldPosition(
ZMorphemeTrajectorySource* p_Item,
ZTrajectoryTrackBase* p_Track,
ZGameTime p_ItemTime,
ZAnimationResource* p_AnimationResource,
ZEntityRef p_TargetEntity
);
static SVector3 EvaluateTrajectoryWorldPosition(
ZEulerAngleTrajectorySource* p_Item,
ZTrajectoryTrackBase* p_Track,
ZGameTime p_ItemTime,
ZEntityRef p_TargetEntity
);
static SVector3 EvaluateTrajectoryWorldPosition(
ZBezierSplineTrajectorySource* p_Item,
ZTrajectoryTrackBase* p_Track,
ZGameTime p_ItemTime,
ZEntityRef p_TargetEntity
);

static bool IsActorTarget(ZActor* p_Actor);

Expand Down Expand Up @@ -481,6 +580,8 @@ class Editor : public IPluginInterface {
AudioEmitterSpatialAspect,
AudioEmitterVolumetricAspect,
ClothWireEntity,
SoundGateEntity,
SequenceEntity,
Count
};

Expand Down Expand Up @@ -625,14 +726,16 @@ class Editor : public IPluginInterface {
bool m_DrawShapes = false;
DebugDrawMode m_ShapeDrawMode = DebugDrawMode::SelectedChannelsAndTypes;

ZEntityRef m_SelectedGizmoEntity = nullptr;
ZEntityRef m_SelectedDebugEntity = nullptr;

bool m_DrawCoverInvalidOnNPCErrors = true;
bool m_DrawHeroGuidesSolid = false;
bool m_AlwaysDrawDebugBoxForColiValidityCheck = false;
bool m_DrawPushDebug = false;
bool m_DrawSafeZones = true;

bool m_ShowSoundOcclusion = false;

ZEntityRef m_EditorData {};
TEntityRef<ZCameraEntity> m_EditorCamera {};
TEntityRef<ZRenderDestinationTextureEntity> m_EditorCameraRT {};
Expand Down
14 changes: 14 additions & 0 deletions ZHMModSDK/Include/Functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ class ZHM5WeaponControl;
class ZGameKeywordManager;
class ZFreeCameraControlEditorStyleEntity;
class ICameraEntity;
class ZEulerAngleTrajectorySource;
class ZMorphemeTrajectorySource;
class ZBezierSplineTrajectorySource;
class ZGameTime;

namespace bfx {
class AreaHandle;
Expand Down Expand Up @@ -319,4 +323,14 @@ class ZHMSDK_API Functions {
static EngineFunction<void(
ZFreeCameraControlEditorStyleEntity* th,
float fZoom)>* ZFreeCameraControlEditorStyleEntity_ZoomCamera;

static EngineFunction<SMatrix* (
ZEulerAngleTrajectorySource* th, SMatrix* result, ZGameTime& animationTime
)>* ZEulerAngleTrajectorySource_GetTrajectoryAtTime;
static EngineFunction<SMatrix* (
ZMorphemeTrajectorySource* th, SMatrix* result, ZGameTime& animationTime
)>* ZMorphemeTrajectorySource_GetTrajectoryAtTime;
static EngineFunction<SMatrix* (
ZBezierSplineTrajectorySource* th, SMatrix* result, ZGameTime& animationTime
)>* ZBezierSplineTrajectorySource_GetTrajectoryAtTime;
};
6 changes: 6 additions & 0 deletions ZHMModSDK/Include/Glacier/IBoolConditionListener.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#pragma once

#include "IComponentInterface.h"

class IBoolConditionListener : public IComponentInterface {
};
8 changes: 4 additions & 4 deletions ZHMModSDK/Include/Glacier/SColorRGBA.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

struct SColorRGBA {
uint32_t GetAsUInt32() const {
const uint32_t r = std::clamp(static_cast<int>(this->r * 256.0f), 0, 255);
const uint32_t g = std::clamp(static_cast<int>(this->g * 256.0f), 0, 255);
const uint32_t b = std::clamp(static_cast<int>(this->b * 256.0f), 0, 255);
const uint32_t a = std::clamp(static_cast<int>(this->a * 256.0f), 0, 255);
const uint32_t r = std::clamp(static_cast<int32_t>(this->r * 256.f), 0, 255);
const uint32_t g = std::clamp(static_cast<int32_t>(this->g * 256.f), 0, 255);
const uint32_t b = std::clamp(static_cast<int32_t>(this->b * 256.f), 0, 255);
const uint32_t a = std::clamp(static_cast<int32_t>(this->a * 256.f), 0, 255);

return (a << 24) | (b << 16) | (g << 8) | r; // 0xAABBGGRR
}
Expand Down
15 changes: 15 additions & 0 deletions ZHMModSDK/Include/Glacier/TSharedValue.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#pragma once

#include <cstdint>

template <typename T>
struct SSharedValueContainer {
uint32_t m_nRefCount;
T m_value;
};

template <typename T>
class TSharedValue {
public:
SSharedValueContainer<T>* m_pValue;
};
82 changes: 82 additions & 0 deletions ZHMModSDK/Include/Glacier/ZCircleGenerator.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#pragma once

#include <numbers>

#include "ZMath.h"

class ZCircleGenerator {
public:
void Init(
const SVector3& p_Center,
const SVector3& p_Size,
const SVector3& p_Normal,
const SVector3& p_StartDir,
float p_Angle,
float fStepsToACircle
) {
m_vCenter = p_Center;

m_vXAxis = p_StartDir * p_Size.x;

SVector3 s_Cross = SVector3::CrossProduct(p_Normal, p_StartDir);
m_vYAxis = s_Cross * p_Size.y;

float4 s_initialPosition = m_vCenter + m_vXAxis;
m_v1 = s_initialPosition;
m_v2 = s_initialPosition;

m_vX.m4 = float4(1.f);
m_vY.m4 = float4(0.f);

m_nStep = 0;
const float s_NumStepsFloat = std::abs(p_Angle * fStepsToACircle / (2.0f * std::numbers::pi_v<float>));
const int32_t s_NumSteps = static_cast<int32_t>(s_NumStepsFloat);
m_nNumSteps = s_NumSteps > 2 ? s_NumSteps : 3;

float s_DeltaTheta = p_Angle / static_cast<float>(m_nNumSteps);
float s_CosT = std::cos(s_DeltaTheta);
float s_SinT = std::sin(s_DeltaTheta);

m_vRow0 = float4(s_CosT, -s_SinT, 0.f, 0.f);
m_vRow1 = float4(s_SinT, s_CosT, 0.f, 0.f);
}

bool MoveNext() {
if (m_nStep == m_nNumSteps) {
return false;
}

m_v1 = m_v2;
m_nStep++;

float s_X = m_vX.m4.x;
float s_Y = m_vY.m4.x;

float s_NewX = s_X * m_vRow0.x + s_Y * m_vRow0.y;
float s_NewY = s_X * m_vRow1.x + s_Y * m_vRow1.y;

m_vX.m4 = float4(s_NewX);
m_vY.m4 = float4(s_NewY);

m_v2 = m_vCenter + (m_vXAxis * s_NewX) + (m_vYAxis * s_NewY);

return true;
}

float4 m_v1;
float4 m_v2;

float4 m_vCenter;

uint32_t m_nStep;
uint32_t m_nNumSteps;

float4 m_vRow0;
float4 m_vRow1;

float1 m_vX;
float1 m_vY;

float4 m_vXAxis;
float4 m_vYAxis;
};
Loading
Loading