UE4 UDecalComponent用法 - 纳金网
联系我们

给我们留言

联系我们

地址:福建省晋江市青阳街道洪山路国际工业设计园纳金网

邮箱:info@narkii.com

电话:0595-82682267

(周一到周五, 周六周日休息)

当前位置:主页 > 3D教程 > 图文教程

UE4 UDecalComponent用法

来源: 52vr | 责任编辑:传说的落叶 | 发布时间: 2019-06-06 08:25 | 浏览量:

[UE4]UDecalComponent用法

 

4.11的TopDown Sample Project中,增加了一个新功能:用UDecalComponent显示印花图案,特点是可以在非平面的地形上,按照地面的凹凸地势自动贴紧地面。

 

定义:

 
  1. /** A decal that projects to the cursor location. */  
  2. UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = "true"))  
  3. class UDecalComponent* CursorToWorld;  

 

构造函数中对其初始化:

 
  1. // Create a decal in the world to show the cursor's location  
  2. CursorToWorld = CreateDefaultSubobject<UDecalComponent>("CursorToWorld");  
  3. CursorToWorld->AttachTo(RootComponent);  
  4. static ConstructorHelpers::FObjectFinder<UMaterial> DecalMaterialAsset(TEXT("Material'/Game/TopDownCPP/Blueprints/M_Cursor_Decal.M_Cursor_Decal'"));  
  5. if (DecalMaterialAsset.Succeeded())  
  6. {  
  7.     CursorToWorld->SetDecalMaterial(DecalMaterialAsset.Object);  
  8. }  
  9. CursorToWorld->DecalSize = FVector(16.0f, 32.0f, 32.0f);  
  10. CursorToWorld->SetRelativeRotation(FRotator(90.0f, 0.0f, 0.0f).Quaternion());  

 

跟随鼠标位置在地面上绘制:

 
  1. void ANetworkTestCharacter::Tick(float DeltaSeconds)  
  2. {  
  3.     if (CursorToWorld != nullptr)  
  4.     {  
  5.         if (APlayerController* PC = Cast<APlayerController>(GetController()))  
  6.         {  
  7.             FHitResult TraceHitResult;  
  8.             PC->GetHitResultUnderCursor(ECC_Visibility, true, TraceHitResult);  
  9.             FVector CursorFV = TraceHitResult.ImpactNormal;  
  10.             FRotator CursorR = CursorFV.Rotation();  
  11.             CursorToWorld->SetWorldLocation(TraceHitResult.Location);  
  12.             CursorToWorld->SetWorldRotation(CursorR);  
  13.         }  
  14.     }  
  15. }  


相关文章
网友评论

您需要登录后才可以发帖 登录 | 立即注册

关闭

全部评论:0条

推荐
热门