ue4-UDecalComponent组件,紧贴Mesh的材质
2017-02-25 14:44
966 查看
在4.11版本后的 TopDown 模板中,多了个紧跟光标移动的一个图案,会贴在不同凹凸面的Mesh中,就是使用了一个新增的组件 UDecalComponent
蓝图子类可以对这个组件的 Decal Material 材质 进行重新赋值
每帧tick获取当前屏幕光标在当前摄像机对应 world 中的位置 Loaction,再将 UDecalComponent 组件set到那个 Location
真相
直接看 TopDown 模板中使用
c++ 中的 Character 中加个 UDecalComponent 组件/** A decal that projects to the cursor location. */ UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = "true")) class UDecalComponent* CursorToWorld; //构造函数中加载一个蓝图材质set到 UDecalComponent 组件中 AMyTestCharacter::AMyTestCharacter() { // Create a decal in the world to show the cursor's location CursorToWorld = CreateDefaultSubobject<UDecalComponent>("CursorToWorld"); CursorToWorld->SetupAttachment(RootComponent); static ConstructorHelpers::FObjectFinder<UMaterial> DecalMaterialAsset(TEXT("Material'/Game/TopDownCPP/Blueprints/M_Cursor_Decal.M_Cursor_Decal'")); if (DecalMaterialAsset.Succeeded()) { CursorToWorld->SetDecalMaterial(DecalMaterialAsset.Object); } CursorToWorld->DecalSize = FVector(16.0f, 32.0f, 32.0f); CursorToWorld->SetRelativeRotation(FRotator(90.0f, 0.0f, 0.0f).Quaternion()); }
蓝图子类可以对这个组件的 Decal Material 材质 进行重新赋值
每帧tick获取当前屏幕光标在当前摄像机对应 world 中的位置 Loaction,再将 UDecalComponent 组件set到那个 Location
void AMyTestCharacter::Tick(float DeltaSeconds) { Super::Tick(DeltaSeconds); if (APlayerController* PC = Cast<APlayerController>(GetController())) { FHitResult TraceHitResult; PC->GetHitResultUnderCursor(ECC_Visibility, true, TraceHitResult); FVector CursorFV = TraceHitResult.ImpactNormal; FRotator CursorR = CursorFV.Rotation(); CursorToWorld->SetWorldLocation(TraceHitResult.Location); CursorToWorld->SetWorldRotation(CursorR); } }
真相
相关文章推荐
- UE4为组件Component注册事件时没有效果的问题解决
- ue4 如何动态改变mesh材质
- UE4 模型组件(ModelComponent)
- 移植UE4的Spline与SplineMesh组件到Unity5
- [UE4]如何替换角色Mesh上的Material材质
- UE4 Tutorial - Custom Mesh Component
- UE4:C++动态添加UStaticMeshComponent
- React-Component(组件)
- android 禁用和开启四大组件的方法(setComponentEnabledSetting )
- 022 component(组件)关联映射
- 关于UE4 OnComponentBeginOverlap 可能会执行两次
- 组件(Component)
- DLL 组件(Component) 对象(Object) OLE控件 ActiveX控件 OCX COM 收藏
- Spring组件扫描<context:component-scan/>使用详解
- 在React中使用extends React.Component定义的组件
- 与CDF中的TableComponent组件交互 -- 转自Pedro Alves on Business Intelligence
- 浅析Hibernate映射(四)——组件映射(component)
- spring 组件自动装载示例(@ComponentScan,@Component,@Scope)
- Restlet - 使用Restlet自身组件Application/Component的开发实例
- unity3d教程游戏目标 (GameObject) 和组件 (Component) 的联系