Skip to content

Commit ff46d18

Browse files
author
laishikai
committed
UGC测试
1 parent 4f3d5f2 commit ff46d18

14 files changed

+379
-52
lines changed

Content/Script/UGC/Operator/UGC_OperatorMrg.lua

+52-2
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,24 @@ function M:ChangeTransfromMode()
128128
self.AxisActor.TransfromComponentZ.Thickness = 4
129129
else
130130
bShowBox = true
131+
132+
self.AxisActor.BoxComponent.Boxs:Clear()
133+
134+
local SelectObjects = _G.UGC.SelectInfo.SelectObjects
135+
local Origin = UE.FVector()
136+
local BoxExtent = UE.FVector()
137+
138+
local Box = UE.FBox()
139+
Box.IsValid = true
140+
for _idx, SelectObj in pairs(SelectObjects) do
141+
SelectObj:GetActorBounds(true, Origin, BoxExtent, true)
142+
Box.Min = Origin - BoxExtent
143+
Box.Max = Origin + BoxExtent
144+
self.AxisActor.BoxComponent.Boxs:Add(Box)
145+
end
146+
self.AxisActor.BoxComponent.bShowBigBox = true
147+
self.AxisActor.BoxComponent:UpdateBounds()
148+
print("[UGC]ChangeTransfromMode, Transfrom_Mode=", Transfrom_Mode, ",bShowBox=", bShowBox, ",#SelectObjects=", #SelectObjects)
131149
end
132150
self.AxisActor.BoxComponent.bRenderVisibility = bShowBox
133151

@@ -151,15 +169,18 @@ function M:TrySelectAxis(MouseEvent)
151169
if self.AxisActor == nil then
152170
return false
153171
end
172+
local Transfrom_Mode = _G.UGC.SelectInfo.Transfrom_Mode
173+
local OperatorType = _G.UGC.OperatorType
174+
if Transfrom_Mode == OperatorType.Tf_None then
175+
return false
176+
end
154177

155178
local World = self:GetWorld()
156179
local ScreenPosition = UE.UKismetInputLibrary.PointerEvent_GetScreenSpacePosition(MouseEvent) -- 取屏幕坐标(这个是屏幕坐标噢,不是当前窗口的坐标)
157180
local ViewportPosition = UE.UUGCFunctionLibary.ScreenToWindow(ScreenPosition) -- 转换成当前的视图坐标(这个才是窗口的相对坐标)
158181

159182
local localPlayerControler = _G.UGameplayStatics.GetPlayerController(World, 0)
160183
-- K2_LineTraceComponent
161-
local Transfrom_Mode = _G.UGC.SelectInfo.Transfrom_Mode
162-
local OperatorType = _G.UGC.OperatorType
163184
local AxisType = _G.UGC.AxisType
164185

165186
local DefaultThickness = 2
@@ -265,6 +286,17 @@ function M:GetFirstSelectActorPosition()
265286
return LastObjPos
266287
end
267288

289+
-- 得到第一个选中对象的中心位置
290+
function M:GetFirstSelectOrigin()
291+
local FirstSelectObj = _G.UGC.SelectInfo.SelectObjects[1]
292+
local Origin = UE.FVector()
293+
local BoxExtent = UE.FVector()
294+
if FirstSelectObj then
295+
FirstSelectObj:GetActorBounds(true, Origin, BoxExtent, true)
296+
end
297+
return Origin
298+
end
299+
268300
function M:GetWorld()
269301
return self.GameInstance:GetWorld()
270302
end
@@ -309,4 +341,22 @@ function M:HideAxisActor()
309341
end
310342
end
311343

344+
function M:ShowDebugLine(StartPt, EndPt)
345+
if self.AxisActor then
346+
self.SplineComponent = self.AxisActor.DebugLineComponent
347+
local Points = self.SplineComponent.Points
348+
Points:Clear()
349+
Points:Add(StartPt)
350+
Points:Add(EndPt)
351+
352+
self.SplineComponent.bRenderVisibility = true
353+
end
354+
end
355+
356+
function M:HideDebugLine()
357+
if self.SplineComponent then
358+
self.SplineComponent.bRenderVisibility = false
359+
end
360+
end
361+
312362
return M

Content/Script/UGC/UI/W_UGC_Backpanel.lua

+31-3
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ function M:OnMouseButtonDown(MyGeometry, MouseEvent)
3232
-- print("[UGC]Find HitResult, hitActor:", hitActor)
3333
-- end
3434

35+
print("[UGC]OnMouseButtonDown, bMouseDown=", self.bMouseDown, ",selectActor=", selectActor, ",bSelectAxis=", bSelectAxis)
36+
3537
local bMouseLD = self:IsLeftMouseDown(MouseEvent)
3638
self.MouseDownPos = UE.FVector2D(screenPos.X, screenPos.Y)
3739
self.bMouseDown = bMouseLD
@@ -41,6 +43,8 @@ function M:OnMouseButtonDown(MyGeometry, MouseEvent)
4143
self.StartTerrainPickPos = self:GetTerranPickPos(MouseEvent)
4244
self.StartFacePickPos = self:GetFacePickPos(MouseEvent)
4345
self.FirstBoundBoxInfo = _G.UGC.OperatorMrg:GetFirstSelectBoundBoxInfo()
46+
47+
_G.UGC.OperatorMrg:HideDebugLine()
4448

4549
-- print("[UGC]OnMouseButtonDown, bMouseDown=", self.bMouseDown, ",StartCameraPos=", self.StartCameraPos)
4650
if self.bMouseDown then
@@ -92,11 +96,12 @@ function M:OnDraging(MyGeometry, MouseEvent)
9296
else
9397
self:OnDragCamera(MouseEvent)
9498
end
99+
_G.UGC.SelectInfo.NeedClearSelectAxis = false
95100
else
96101
self:OnDragCamera(MouseEvent)
97102
end
98103

99-
self.StartWorldPos = WorldPosition
104+
-- self.StartWorldPos = WorldPosition
100105
self.MouseDownPos = screenPos
101106

102107
-- print("[UGC]OnDragingMove, CameraPos=", CameraPos, ",moveOffset=", moveOffset)
@@ -234,6 +239,27 @@ end
234239

235240
-- 旋转物体
236241
function M:RotationSelectObjects(MouseEvent)
242+
-- 计算两个屏幕拾取点在X0Y地平面的搞影点与球心的夹角
243+
local ScreenPosition = UE4.UKismetInputLibrary.PointerEvent_GetScreenSpacePosition(MouseEvent) -- 取屏幕坐标
244+
local NewTerranPos = self:GetTerranPickPos(MouseEvent)
245+
local MoveOffset = NewTerranPos - self.StartTerrainPickPos
246+
local Dist = MoveOffset:Size()
247+
if Dist < 0.1 then
248+
return
249+
end
250+
local OldBoundBoxInfo = self.FirstBoundBoxInfo
251+
local Origin = OldBoundBoxInfo.Origin
252+
local DirA = self.StartTerrainPickPos - Origin
253+
local DirB = NewTerranPos - Origin
254+
DirA:Normalize()
255+
DirB:Normalize()
256+
local fAngle = UE.FVector.Dot(DirA, DirB)
257+
fAngle = math.acos(fAngle)
258+
local fDegree = fAngle * 180.0 / math.pi
259+
260+
_G.UGC.OperatorMrg:ShowDebugLine(self.StartTerrainPickPos, NewTerranPos)
261+
262+
print("[UGC]Rotaion, Degree=", fDegree, ",fAngle=", fAngle)
237263
end
238264

239265
function M:OnDragCamera(MouseEvent)
@@ -244,15 +270,17 @@ end
244270

245271
-- 获得拾取的地面位置
246272
function M:GetTerranPickPos(MouseEvent)
247-
local Origin = _G.UGC.OperatorMrg:GetFirstSelectActorPosition()
273+
local Origin = _G.UGC.OperatorMrg:GetFirstSelectOrigin()
248274
local ScreenPosition = UE4.UKismetInputLibrary.PointerEvent_GetScreenSpacePosition(MouseEvent) -- 取屏幕坐标
275+
ScreenPosition = UE.UUGCFunctionLibary.ScreenToWindow(ScreenPosition)
249276
return _G.UGC.OperatorMrg:GetTerranPickPos(Origin, ScreenPosition)
250277
end
251278

252279
-- 获得正面拾取的位置
253280
function M:GetFacePickPos(MouseEvent)
254-
local Origin = _G.UGC.OperatorMrg:GetFirstSelectActorPosition()
281+
local Origin = _G.UGC.OperatorMrg:GetFirstSelectOrigin()
255282
local ScreenPosition = UE4.UKismetInputLibrary.PointerEvent_GetScreenSpacePosition(MouseEvent) -- 取屏幕坐标
283+
ScreenPosition = UE.UUGCFunctionLibary.ScreenToWindow(ScreenPosition)
256284
return _G.UGC.OperatorMrg:GetCameraPickPos(Origin, ScreenPosition)
257285
end
258286

Plugins/UGC/Source/UGC/Private/AxisActor.cpp

+17
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
// Copyright Epic Games, Inc. All Rights Reserved.
22
#include "AxisActor.h"
33
#include "Components/SceneComponent.h"
4+
#include "Components/SplineComponent.h"
45
#include "AxisBoxComponent.h"
56
#include "AxisTranstromComponent.h"
67
#include "AxisRotationComponent.h"
8+
#include "AxisDebugLineComponent.h"
79

810
AAxisActor::AAxisActor()
911
{
@@ -12,38 +14,53 @@ AAxisActor::AAxisActor()
1214

1315
BoxComponent = CreateDefaultSubobject<UAxisBoxComponent>(TEXT("Box"));
1416
BoxComponent->SetupAttachment(SceneComponent);
17+
BoxComponent->SceneDepthGroup = SDPG_World;
1518

1619
TransfromComponentZ = CreateDefaultSubobject<UAxisTranstromComponent>(TEXT("TransformZ"));
1720
TransfromComponentZ->SetupAttachment(SceneComponent);
1821
TransfromComponentZ->Color = FLinearColor::Blue;
22+
TransfromComponentZ->SceneDepthGroup = SDPG_World;
1923

2024
UAxisTranstromComponent *TransX = CreateDefaultSubobject<UAxisTranstromComponent>(TEXT("TransformX"));
2125
TransX->SetupAttachment(SceneComponent);
2226
TransX->Direction = FVector(1, 0, 0);
2327
TransfromComponentX = TransX;
2428
TransfromComponentX->Color = FLinearColor::Blue;
29+
TransfromComponentX->SceneDepthGroup = SDPG_World;
2530

2631
UAxisTranstromComponent* TransY = CreateDefaultSubobject<UAxisTranstromComponent>(TEXT("TransformY"));
2732
TransY->SetupAttachment(SceneComponent);
2833
TransY->Direction = FVector(0, 1, 0);
2934
TransfromComponentY = TransY;
3035
TransfromComponentY->Color = FLinearColor::Blue;
36+
TransfromComponentY->SceneDepthGroup = SDPG_World;
3137

3238
UAxisRotationComponent *RotationComponent = CreateDefaultSubobject<UAxisRotationComponent>(TEXT("RotaitonX"));
3339
RotationComponent->Normal = FVector(1, 0, 0);
3440
RotationComponent->Color = FLinearColor(0, 0.13286, 1, 1);
3541
RotationComponentX = RotationComponent;
3642
RotationComponentX->SetupAttachment(SceneComponent);
43+
RotationComponentX->SceneDepthGroup = SDPG_Foreground;
3744

3845
RotationComponent = CreateDefaultSubobject<UAxisRotationComponent>(TEXT("RotaitonY"));
3946
RotationComponent->Normal = FVector(0, 1, 0);
4047
RotationComponent->Color = FLinearColor(0.337497, 0.594882, 1, 1);
4148
RotationComponentY = RotationComponent;
4249
RotationComponentY->SetupAttachment(SceneComponent);
50+
RotationComponentY->SceneDepthGroup = SDPG_Foreground;
4351

4452
RotationComponent = CreateDefaultSubobject<UAxisRotationComponent>(TEXT("RotaitonZ"));
4553
RotationComponent->Normal = FVector(0, 0, 1);
4654
RotationComponent->Color = FLinearColor(1, 0, 0, 1);
4755
RotationComponentZ = RotationComponent;
4856
RotationComponentZ->SetupAttachment(SceneComponent);
57+
RotationComponentZ->SceneDepthGroup = SDPG_Foreground;
58+
59+
UAxisDebugLineComponent*LineComponent = CreateDefaultSubobject<UAxisDebugLineComponent>(TEXT("DebugLine"));
60+
LineComponent->SetupAttachment(SceneComponent);
61+
DebugLineComponent = LineComponent;
62+
63+
LineComponent->Color = FLinearColor(0, 1, 0, 1);
64+
LineComponent->bRenderVisibility = false;
65+
LineComponent->SceneDepthGroup = SDPG_World;
4966
}

Plugins/UGC/Source/UGC/Private/AxisBoxComponent.cpp

+70-39
Original file line numberDiff line numberDiff line change
@@ -26,30 +26,58 @@ class FUGCGizmoBoxComponentSceneProxy final : public FPrimitiveSceneProxy
2626
}
2727

2828
const FLinearColor& Color = AxisCompnent->Color;
29-
const float Width = AxisCompnent->Width;
30-
const float Height = AxisCompnent->Height;
31-
const float Length = AxisCompnent->Length;
3229
const float Thickness = AxisCompnent->Thickness;
3330
const float HoverThicknessMultiplier = AxisCompnent->HoverSizeMultiplier;
3431

3532
bool& bExternalRenderVisibility = AxisCompnent->bExternalRenderVisibility;
36-
float RY = Width * 0.5f;
37-
float RZ = Height * 0.5f;
38-
float RX = Length * 0.5f;
33+
const FSceneView* FocusedView = AxisGizmoRenderingUtil::FindFocusedEditorSceneView(Views, ViewFamily, VisibilityMap);
34+
bool& bExternalHoverState = AxisCompnent->bHovering;
35+
36+
//const FMatrix& LocalToWorldMatrix = GetLocalToWorld();
37+
//FVector Origin = LocalToWorldMatrix.TransformPosition(FVector::ZeroVector);
38+
39+
bExternalRenderVisibility = true;
40+
ESceneDepthPriorityGroup DepthType = AxisCompnent->SceneDepthGroup;
41+
42+
for (int32 ViewIndex = 0; ViewIndex < Views.Num(); ViewIndex++)
43+
{
44+
if (VisibilityMap & (1 << ViewIndex))
45+
{
46+
const FSceneView* View = Views[ViewIndex];
47+
FPrimitiveDrawInterface* PDI = Collector.GetPDI(ViewIndex);
48+
for(int32 i = 0; i< AxisCompnent->Boxs.Num(); ++i)
49+
{
50+
DrawBox(PDI, AxisCompnent->Boxs[i], Color, DepthType, Thickness);
51+
}
3952

40-
FVector V[8] =
53+
if(AxisCompnent->Boxs.Num() > 1 && AxisCompnent->bShowBigBox)
54+
{
55+
DrawBox(PDI, AxisCompnent->BigBox, Color, DepthType, Thickness);
56+
}
57+
}
58+
}
59+
}
60+
void DrawBox(FPrimitiveDrawInterface* PDI, const FBox &Box, const FLinearColor& Color, ESceneDepthPriorityGroup DepthType, float Thickness) const
61+
{
62+
FVector Center = Box.GetCenter();
63+
FVector Extent = Box.GetExtent();
64+
float RY = Extent.Y;
65+
float RZ = Extent.Z;
66+
float RX = Extent.X;
67+
68+
FVector V[8] =
4169
{
4270
FVector(-RX, RY, -RZ), // v0
4371
FVector(-RX, -RY, -RZ), // v1
44-
FVector( RX, -RY, -RZ), // v2
45-
FVector( RX, RY, -RZ), // v3
72+
FVector(RX, -RY, -RZ), // v2
73+
FVector(RX, RY, -RZ), // v3
4674

4775
FVector(-RX, RY, RZ), // v4
4876
FVector(-RX, -RY, RZ), // v5
49-
FVector( RX, -RY, RZ), // v6
50-
FVector( RX, RY, RZ), // v7
77+
FVector(RX, -RY, RZ), // v6
78+
FVector(RX, RY, RZ), // v7
5179
};
52-
int Indics[24] = {0, 1, 0, 3, 1, 2, 2, 3, 2, 6, 6, 7, 3, 7, 1, 5, 5, 4, 0, 4, 4, 7, 5, 6 };
80+
const int Indics[24] = { 0, 1, 0, 3, 1, 2, 2, 3, 2, 6, 6, 7, 3, 7, 1, 5, 5, 4, 0, 4, 4, 7, 5, 6 };
5381
// v4------v7
5482
// / /|
5583
// v0------v3 |
@@ -58,32 +86,14 @@ class FUGCGizmoBoxComponentSceneProxy final : public FPrimitiveSceneProxy
5886
// | |/ | /
5987
// v1------v2 0 ---- x
6088

61-
const FSceneView* FocusedView = AxisGizmoRenderingUtil::FindFocusedEditorSceneView(Views, ViewFamily, VisibilityMap);
62-
63-
const FMatrix& LocalToWorldMatrix = GetLocalToWorld();
64-
FVector Origin = LocalToWorldMatrix.TransformPosition(FVector::ZeroVector);
65-
66-
bExternalRenderVisibility = true;
67-
68-
for (int32 ViewIndex = 0; ViewIndex < Views.Num(); ViewIndex++)
89+
for (int i = 0; i < 24;)
6990
{
70-
if (VisibilityMap & (1 << ViewIndex))
71-
{
72-
const FSceneView* View = Views[ViewIndex];
73-
FPrimitiveDrawInterface* PDI = Collector.GetPDI(ViewIndex);
74-
bool bIsFocusedView = (FocusedView != nullptr && View == FocusedView);
75-
bool bIsOrtho = !View->IsPerspectiveProjection();
91+
FVector V1 = V[Indics[i++]];
92+
FVector V2 = V[Indics[i++]];
93+
V1 += Center;
94+
V2 += Center;
7695

77-
for (int i = 0; i < 24;)
78-
{
79-
FVector V1 = V[Indics[i++]];
80-
FVector V2 = V[Indics[i++]];
81-
V1 = LocalToWorldMatrix.TransformPosition(V1);
82-
V2 = LocalToWorldMatrix.TransformPosition(V2);
83-
84-
PDI->DrawLine(V1, V2, Color, SDPG_Foreground, Thickness, 0.0f, true);
85-
}
86-
}
96+
PDI->DrawLine(V1, V2, Color, DepthType, Thickness, 0.0f, true);
8797
}
8898
}
8999

@@ -133,9 +143,30 @@ bool UAxisBoxComponent::LineTraceComponent(FHitResult& OutHit, const FVector Sta
133143
return true;
134144
}
135145

146+
void UAxisBoxComponent::UpdateBounds()
147+
{
148+
if(Boxs.Num() > 0)
149+
{
150+
BigBox = Boxs[0];
151+
}
152+
else
153+
{
154+
BigBox = FBox();
155+
}
156+
for(int32 i = 1; i<Boxs.Num(); ++i)
157+
{
158+
const FBox &Box = Boxs[i];
159+
BigBox += Box;
160+
}
161+
}
162+
136163
FBoxSphereBounds UAxisBoxComponent::CalcBounds(const FTransform& LocalToWorld) const
137164
{
138-
float Radius = Width < Height ? Height :Width;
139-
Radius = Radius < Length ? Length : Radius;
140-
return FBoxSphereBounds(FSphere(FVector::ZeroVector, Radius).TransformBy(LocalToWorld));
165+
//return FBoxSphereBounds(BigBox.TransformBy(LocalToWorld));
166+
FVector Size = BigBox.GetSize();
167+
float Radius = FMath::Max3(Size.X, Size.Y, Size.Z);
168+
Radius = FMath::Max(Radius, 1.0f);
169+
Radius *= 2.0f;
170+
//return FBoxSphereBounds(FSphere(FVector::ZeroVector, Radius).TransformBy(LocalToWorld));
171+
return FBoxSphereBounds(BigBox);
141172
}

0 commit comments

Comments
 (0)