网页资讯视频图片知道文库贴吧地图采购
进入贴吧全吧搜索

 
 
 
日一二三四五六
       
       
       
       
       
       

签到排名:今日本吧第个签到,

本吧因你更精彩,明天继续来努力!

本吧签到人数:0

一键签到
成为超级会员,使用一键签到
一键签到
本月漏签0次!
0
成为超级会员,赠送8张补签卡
如何使用?
点击日历上漏签日期,即可进行补签。
连续签到:天  累计签到:天
0
超级会员单次开通12个月以上,赠送连续签到卡3张
使用连续签到卡
08月04日漏签0天
udk吧 关注:14,269贴子:152,815
  • 看贴

  • 图片

  • 吧主推荐

  • 游戏

  • 15回复贴,共1页
<<返回udk吧
>0< 加载中...

如何绘制编辑器里面的各种线条和图形

  • 只看楼主
  • 收藏

  • 回复
  • 热情的坑爹乐园
  • 中触
    11
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
问题一:如何绘制类似编辑器那种很**的线条

可能大家马上就会联想到

draw debug
Line这个节点
确实,这个节点可以实现类似的效果,但只能在development/debug模式下执行。
其实,这只要打开ue4源码看一看就一清二楚了。我们打开BoxCollisionComponent的源码来看一看究竟,

点进去马上可以看到scene这个字眼,这个FPrimitiveSceneProxy类就是解决这个问题的关键。同样,我们打开他的cpp文件找到CreateSceneProxy()的部分

嗯,没毛病,像我这样cpp的渣渣可以直接抄过去。
不过,像我这种超懒超懒的每个源文件都加上这么一段会要了我的命,就这样我选择把他变成可以在蓝图里耍的东西。
FPrimitiveSceneProxy这个类是在PrimitiveComponent这个组件里面的,那么我们就新建一个基于UPrimitiveComponent的类。
首先先建一个用于SceneDepth的枚举
UENUM(BlueprintType)
enum class ESceneDepthPriorityGroupProxy : uint8
{
World,
Foreground
};
然后怎么在蓝图里获取FPrimitiveDrawInterface这个类呢?我想了想,觉得用结构体比较合适。
USTRUCT(BlueprintType)
struct FPrimitiveDrawProxy
{
GENERATED_USTRUCT_BODY()
public:
FPrimitiveDrawProxy():PDI(nullptr){}
FPrimitiveDrawProxy(class FPrimitiveDrawInterface * PDI) : PDI(PDI){}
class FPrimitiveDrawInterface * PDI;
};
具体什么原理还是直接看源码比较清楚吧。。。


  • 热情的坑爹乐园
  • 中触
    11
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
DECLARE_DELEGATE_ThreeParams(FCreateDynMeshElementDelegate, const FSceneView*, class FPrimitiveDrawInterface*, const FMatrix&);
/**
*绘制图形
*/
UCLASS(ClassGroup = "LEditorPlugin", Blueprintable, BlueprintType, hidecategories = (Object, LOD, Lighting, TextureStreaming,Collision,ComponentReplication,Cooking,Physics), editinlinenew, meta = (BlueprintSpawnableComponent))
class LEDITORPLUGIN_API UPDIdrawingComponent : public UPrimitiveComponent
{
GENERATED_BODY()
public:
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "PDIdrawing")
bool bDrawOnlyIfSelected;
FCreateDynMeshElementDelegate CreateDynMeshElemDelegate;
public:
UPDIdrawingComponent(const FObjectInitializer& ObjectInitializer);
//~Begin UPrimitiveComponent Interfave
virtual FPrimitiveSceneProxy* CreateSceneProxy() override;
//~ End UPrimitiveComponent Interface.
//~ Begin USceneComponent Interface.
virtual FBoxSphereBounds CalcBounds(const FTransform& LocalToWorld) const override;
//~ Begin USceneComponent Interface.
UFUNCTION(BlueprintCallable, Category = "PDIdrawing")
void Refresh();
UFUNCTION(BlueprintCallable, BlueprintNativeEvent, Category = "PDIdrawing")
void CreateDynamicElem(FPrimitiveDrawProxy PrimitiveDrawProxy);
public:
UFUNCTION(BlueprintCallable, Category = "PrimitiveDrawProxy")
static void DrawLine(
FPrimitiveDrawProxy PrimitiveDrawProxy,
const FVector& Start,
const FVector& End,
const FLinearColor& Color,
ESceneDepthPriorityGroupProxy DepthPriority,
float Thickness = 0.0f,
float DepthBias = 0.0f,
bool bScreenSpace = false
);
UFUNCTION(BlueprintCallable, Category = "PrimitiveDrawProxy")
static void DrawPoint(
FPrimitiveDrawProxy PrimitiveDrawProxy,
const FVector& Position,
const FLinearColor& Color,
float PointSize,
ESceneDepthPriorityGroupProxy DepthPriority
);
UFUNCTION(BlueprintCallable, Category = "PrimitiveDrawProxy")
static void DrawCircle(
FPrimitiveDrawProxy PrimitiveDrawProxy,
const FVector& Base,
const FVector& X,
const FVector& Y,
const FLinearColor& Color,
float Radius,
int32 NumSides,
ESceneDepthPriorityGroupProxy DepthPriority,
float Thickness = 0.0f,
float DepthBias = 0.0f,
bool bScreenSpace = false);
UFUNCTION(BlueprintCallable, Category = "PrimitiveDrawProxy")
static void DrawDashedLine(
FPrimitiveDrawProxy PrimitiveDrawProxy,
const FVector& Start,
const FVector& End,
const FLinearColor& Color,
ESceneDepthPriorityGroupProxy DepthPriority,
float Thickness = 1.0f,
float DashSize = 0.0f,
float DepthBias = 0.0f,
bool bScreenSpace = true);
UFUNCTION(BlueprintCallable, Category = "PrimitiveDrawProxy")
static void DrawGrid(
FPrimitiveDrawProxy PrimitiveDrawProxy,
const FVector& Base,
float GridInterval,
int32 Size,
const FLinearColor& Color,
ESceneDepthPriorityGroupProxy DepthPriority,
float Thickness = 1.0f,
float DepthBias = 0.0f,
bool bScreenSpace = true);
};


2025-08-04 05:05:49
广告
不感兴趣
开通SVIP免广告
  • 热情的坑爹乐园
  • 中触
    11
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
.cpp
#include "PDIdrawingComponent.h"
#include "PrimitiveViewRelevance.h"
#include "SceneManagement.h"
#include "PrimitiveSceneProxy.h"
UPDIdrawingComponent::UPDIdrawingComponent(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{
bHiddenInGame = false;
bCastDynamicShadow = false;
bDrawOnlyIfSelected = false;
}
FPrimitiveSceneProxy* UPDIdrawingComponent::CreateSceneProxy()
{
/** Represents 'How to draw primitives' to the scene manager. */
class FDraw3DAgentSceneProxy : public FPrimitiveSceneProxy
{
public:
FDraw3DAgentSceneProxy(UPDIdrawingComponent* InComponent)
: FPrimitiveSceneProxy(InComponent)
, InComponent(InComponent)
{
bWillEverBeLit = false;
}
// FPrimitiveSceneProxy interface.
virtual void GetDynamicMeshElements(const TArray<const FSceneView*>& Views, const FSceneViewFamily& ViewFamily, uint32 VisibilityMap, FMeshElementCollector& Collector) const override
{
QUICK_SCOPE_CYCLE_COUNTER(STAT_Draw3DAgentSceneProxy_GetDynamicMeshElements);
for (int32 ViewIndex = 0; ViewIndex < Views.Num(); ViewIndex++)
{
if (VisibilityMap & (1 << ViewIndex))
{
const FSceneView* View = Views[ViewIndex];
FPrimitiveDrawInterface* PDI = Collector.GetPDI(ViewIndex);
const FMatrix& LocalToWorld = GetLocalToWorld();
// Taking into account the min and maximum drawing distance
const float DistanceSqr = (View->ViewMatrices.GetViewOrigin() - LocalToWorld.GetOrigin()).SizeSquared();
if (DistanceSqr < FMath::Square(GetMinDrawDistance()) || DistanceSqr > FMath::Square(GetMaxDrawDistance()))
{
continue;
}
InComponent->CreateDynMeshElemDelegate.ExecuteIfBound(View, PDI, LocalToWorld);
InComponent->CreateDynamicElem(PDI);
}
}
}
virtual FPrimitiveViewRelevance GetViewRelevance(const FSceneView* View) const override
{
const bool bVisibleForSelection = !InComponent->bDrawOnlyIfSelected || IsSelected();
const bool bShowForCollision = View->Family->EngineShowFlags.Collision && IsCollisionEnabled();
FPrimitiveViewRelevance Result;
Result.bDrawRelevance = (IsShown(View) && bVisibleForSelection) || bShowForCollision;
Result.bDynamicRelevance = true;
Result.bShadowRelevance = IsShadowCast(View);
Result.bEditorPrimitiveRelevance = UseEditorCompositing(View);
return Result;
}
virtual uint32 GetMemoryFootprint(void) const override { return(sizeof(*this) + GetAllocatedSize()); }
uint32 GetAllocatedSize(void) const { return(FPrimitiveSceneProxy::GetAllocatedSize()); }
private:
UPDIdrawingComponent* InComponent;
};
return new FDraw3DAgentSceneProxy(this);
}
FBoxSphereBounds UPDIdrawingComponent::CalcBounds(const FTransform & LocalToWorld) const
{
FBoxSphereBounds NewBounds;
NewBounds.Origin = FVector::ZeroVector;
NewBounds.BoxExtent = FVector(HALF_WORLD_MAX, HALF_WORLD_MAX, HALF_WORLD_MAX);
NewBounds.SphereRadius = FMath::Sqrt(3.0f * FMath::Square(HALF_WORLD_MAX));
return NewBounds;
}
void UPDIdrawingComponent::Refresh()
{
MarkRenderStateDirty();
}
void UPDIdrawingComponent::CreateDynamicElem_Implementation(FPrimitiveDrawProxy PrimitiveDrawProxy)
{
// Do nothing.
}
// ===================================
void UPDIdrawingComponent::DrawLine(
FPrimitiveDrawProxy PrimitiveDrawProxy,
const FVector& Start, const FVector& End, const FLinearColor& Color,
ESceneDepthPriorityGroupProxy DepthPriorityGroup, float Thickness, float DepthBias, bool bScreenSpace)
{
PrimitiveDrawProxy.PDI->DrawLine(Start, End, Color, (uint8)DepthPriorityGroup, Thickness, DepthBias, bScreenSpace);
}
void UPDIdrawingComponent::DrawPoint(
FPrimitiveDrawProxy PrimitiveDrawProxy,
const FVector& Position, const FLinearColor& Color, float PointSize,
ESceneDepthPriorityGroupProxy DepthPriorityGroup)
{
PrimitiveDrawProxy.PDI->DrawPoint(Position, Color, PointSize, (uint8)DepthPriorityGroup);
}
void UPDIdrawingComponent::DrawCircle(
FPrimitiveDrawProxy PrimitiveDrawProxy,
const FVector& Base, const FVector& X, const FVector& Y,
const FLinearColor& Color, float Radius, int32 NumSides,
ESceneDepthPriorityGroupProxy DepthPriority,
float Thickness, float DepthBias, bool bScreenSpace)
{
::DrawCircle(PrimitiveDrawProxy.PDI, Base, X, Y, Color, Radius, NumSides, (uint8)DepthPriority, Thickness, DepthBias, bScreenSpace);
}
void UPDIdrawingComponent::DrawDashedLine(
FPrimitiveDrawProxy PrimitiveDrawProxy,
const FVector& Start,
const FVector& End,
const FLinearColor& Color,
ESceneDepthPriorityGroupProxy DepthPriority,
float Thickness,
float DashSize,
float DepthBias,
bool bScreenSpace)
{
FVector LineDir = End - Start;
float LineLeft = (End - Start).Size();
if (LineLeft)
{
LineDir /= LineLeft;
}
const int32 nLines = FMath::CeilToInt(LineLeft / (DashSize * 2));
PrimitiveDrawProxy.PDI->AddReserveLines((uint8)DepthPriority, nLines, DepthBias != 0);
const FVector Dash = (DashSize * LineDir);
FVector DrawStart = Start;
while (LineLeft > DashSize)
{
const FVector DrawEnd = DrawStart + Dash;
PrimitiveDrawProxy.PDI->DrawLine(DrawStart, DrawEnd, Color, (uint8)DepthPriority, Thickness, DepthBias, bScreenSpace);
LineLeft -= 2 * DashSize;
DrawStart = DrawEnd + Dash;
}
if (LineLeft > 0.0f)
{
const FVector DrawEnd = End;
PrimitiveDrawProxy.PDI->DrawLine(DrawStart, DrawEnd, Color, (uint8)DepthPriority, Thickness, DepthBias, bScreenSpace);
}
}
void UPDIdrawingComponent::DrawGrid(FPrimitiveDrawProxy PrimitiveDrawProxy, const FVector & Base, float GridInterval, int32 Size, const FLinearColor & Color, ESceneDepthPriorityGroupProxy DepthPriority, float Thickness,float DepthBias, bool bScreenSpace)
{
//---x
PrimitiveDrawProxy.PDI->DrawLine(FVector(Base.X + (-1 * GridInterval*Size), Base.Y, Base.Z), FVector(Base.X + (GridInterval*Size), Base.Y, Base.Z), FLinearColor::Red, (uint8)DepthPriority, Thickness, DepthBias, bScreenSpace);
//----
//---y
PrimitiveDrawProxy.PDI->DrawLine(FVector(Base.X, Base.Y + (-1 * GridInterval*Size), Base.Z), FVector(Base.X, Base.Y + (GridInterval*Size), Base.Z), FLinearColor::Green, (uint8)DepthPriority, Thickness, DepthBias, bScreenSpace);
//----
for (int32 i = 1; i < Size; ++i)
{
FVector Stx = FVector(Base.X + (GridInterval*i),Base.Y - (GridInterval*Size),Base.Z);
PrimitiveDrawProxy.PDI->DrawLine(Stx, FVector(Stx.X, Stx.Y+2*(GridInterval*Size), Base.Z), Color, (uint8)DepthPriority, Thickness, DepthBias, bScreenSpace);
FVector St_x = FVector(Base.X + (GridInterval*i*-1), Base.Y - (GridInterval*Size), Base.Z);
PrimitiveDrawProxy.PDI->DrawLine(St_x, FVector(St_x.X, St_x.Y + 2 * (GridInterval*Size), Base.Z), Color, (uint8)DepthPriority, Thickness, DepthBias, bScreenSpace);
FVector Sty = FVector(Base.X - (GridInterval*Size), Base.Y + (GridInterval*i), Base.Z);
PrimitiveDrawProxy.PDI->DrawLine( FVector(Sty.X+ 2 * (GridInterval*Size), Sty.Y , Base.Z),Sty, Color, (uint8)DepthPriority, Thickness, DepthBias, bScreenSpace);
FVector St_y = FVector(Base.X - (GridInterval*Size) , Base.Y+ (GridInterval*i*-1), Base.Z);
PrimitiveDrawProxy.PDI->DrawLine(FVector(St_y.X + 2 * (GridInterval*Size), St_y.Y, Base.Z),St_y , Color, (uint8)DepthPriority, Thickness, DepthBias, bScreenSpace);
}
}


  • 热情的坑爹乐园
  • 中触
    11
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
然后只需要新建一个蓝图就可以用了,美哉美哉


  • 热情的坑爹乐园
  • 中触
    11
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼



  • 热情的坑爹乐园
  • 中触
    11
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼


  • 热情的坑爹乐园
  • 中触
    11
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

对 @热情的坑... 使用挽尊卡

挽回他的尊严!

效果:udk吧经验+14



  • leavemealone8
  • 大触
    12
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
很**?


2025-08-04 04:59:49
广告
不感兴趣
开通SVIP免广告
  • 热情的坑爹乐园
  • 中触
    11
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
1人惨案


  • -STPEAK
  • 小湿级
    13
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
只能发图片了,发出来就删



  • leavemealone8
  • 大触
    12
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
上热推了


  • 独自战斗的虎式
  • 大触
    12
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
已加精


  • leavemealone8
  • 大触
    12
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
顶


  • 长绿毛的馍
  • 随便玩玩
    2
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
楼主,我看了你的贴子有如醍醐灌顶!然而真正写代码时还是无法下手,能给个联系方式吗,我想跟你再进一步交流下


2025-08-04 04:53:49
广告
不感兴趣
开通SVIP免广告
  • 天天_爱学习
  • 路过酱油
    1
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
可以在游戏中使用这个功能吗


登录百度账号

扫二维码下载贴吧客户端

下载贴吧APP
看高清直播、视频!
  • 贴吧页面意见反馈
  • 违规贴吧举报反馈通道
  • 贴吧违规信息处理公示
  • 15回复贴,共1页
<<返回udk吧
分享到:
©2025 Baidu贴吧协议|隐私政策|吧主制度|意见反馈|网络谣言警示