Procedural Mesh Component in C++:Getting Started
转自:https://wiki.unrealengine.com/Procedural_Mesh_Component_in_C++:Getting_Started
I create a simple triangle using the UProceduralMeshComponent API, from there extending it should be easy. Once the class is compiled you can just drag it into your scene.
To use this component, include the paths in the build.cs file of your project:
MyProject.Build.cs:
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "ProceduralMeshComponent" });
and in your .uproject file (MyProject.uproject) in case you work on a project:
"AdditionalDependencies": [..., ..., "ProceduralMeshComponent"]
After 4.17, plugins can now depend on other plugins, so in case you are working on a plugin instead of a project, you will have to add this to your .uplugin file:
"Modules": [
{
....
}
],
"Plugins": [ // <--
{ // <--
"Name": "ProceduralMeshComponent", // <--
"Enabled": true // <--
} // <--
]
To fix errors with Visual Studio IntelliSense you need to right-click MyProject.uproject and re-generate Visual Studio project files. In Visual Studio 2017, open "Solution Explorer" and open the "Game" folder, right-click on the first line, which should be the root of your solution, select: "Rescan Solution".
I've created an Actor class.
Add the header to your MyActor.h file above the "MyActor.generated.h" include which has to be the last include.
#include "ProceduralMeshComponent.h"
#include "MyActor.generated.h"
In the header file, the following is added to support assigning a material.
private:
UPROPERTY(VisibleAnywhere)
UProceduralMeshComponent * mesh;
In my cpp file I have added the following to the constructor:
MyActor.cpp
// Creating a standard root object.
AMyActor::AMyActor()
{
mesh = CreateDefaultSubobject<UProceduralMeshComponent>(TEXT("GeneratedMesh"));
RootComponent = mesh;
// New in UE 4.17, multi-threaded PhysX cooking.
mesh->bUseAsyncCooking = true;
} // This is called when actor is spawned (at runtime or when you drop it into the world in editor)
void AMyActor::PostActorCreated()
{
Super::PostActorCreated();
CreateTriangle();
} // This is called when actor is already in level and map is opened
void AMyActor::PostLoad()
{
Super::PostLoad();
CreateTriangle();
} void AMyActor::CreateTriangle()
{
TArray<FVector> vertices;
vertices.Add(FVector(, , ));
vertices.Add(FVector(, , ));
vertices.Add(FVector(, , )); TArray<int32> Triangles;
Triangles.Add();
Triangles.Add();
Triangles.Add(); TArray<FVector> normals;
normals.Add(FVector(, , ));
normals.Add(FVector(, , ));
normals.Add(FVector(, , )); TArray<FVector2D> UV0;
UV0.Add(FVector2D(, ));
UV0.Add(FVector2D(, ));
UV0.Add(FVector2D(, )); TArray<FProcMeshTangent> tangents;
tangents.Add(FProcMeshTangent(, , ));
tangents.Add(FProcMeshTangent(, , ));
tangents.Add(FProcMeshTangent(, , )); TArray<FLinearColor> vertexColors;
vertexColors.Add(FLinearColor(0.75, 0.75, 0.75, 1.0));
vertexColors.Add(FLinearColor(0.75, 0.75, 0.75, 1.0));
vertexColors.Add(FLinearColor(0.75, 0.75, 0.75, 1.0)); mesh->CreateMeshSection_LinearColor(, vertices, Triangles, normals, UV0, vertexColors, tangents, true); // Enable collision data
mesh->ContainsPhysicsTriMeshData(true);
}
The documentation for CreateMeshSection and CreateMeshSection_LinearColor functions is this:
/**
* Create/replace a section for this procedural mesh component.
* @param SectionIndex Index of the section to create or replace.
* @param Vertices Vertex buffer of all vertex positions to use for this mesh section.
* @param Triangles Index buffer indicating which vertices make up each triangle. Length must be a multiple of 3.
* @param Normals Optional array of normal vectors for each vertex. If supplied, must be same length as Vertices array.
* @param UV0 Optional array of texture co-ordinates for each vertex. If supplied, must be same length as Vertices array.
* @param VertexColors Optional array of colors for each vertex. If supplied, must be same length as Vertices array.
* @param Tangents Optional array of tangent vector for each vertex. If supplied, must be same length as Vertices array.
* @param bCreateCollision Indicates whether collision should be created for this section. This adds significant cost.
*/ // '''Don't use this function'''. It is deprecated. Use LinearColor version.
void CreateMeshSection(int32 SectionIndex, const TArray<FVector>& Vertices, const TArray<int32>& Triangles, const TArray<FVector>& Normals, const TArray<FVector2D>& UV0, const TArray<FColor>& VertexColors, const TArray<FProcMeshTangent>& Tangents, bool bCreateCollision); // In this one you can send FLinearColor instead of FColor for the Vertex Colors.
void CreateMeshSection_LinearColor(int32 SectionIndex, const TArray<FVector>& Vertices, const TArray<int32>& Triangles, const TArray<FVector>& Normals, const TArray<FVector2D>& UV0, const TArray<FLinearColor>& VertexColors, const TArray<FProcMeshTangent>& Tangents, bool bCreateCollision) // Updates a section of this procedural mesh component. This is faster than CreateMeshSection, but does not let you change topology. Collision info is also updated.
void UpdateMeshSection_LinearColor(int32 SectionIndex, const TArray<FVector>& Vertices, const TArray<FVector>& Normals, const TArray<FVector2D>& UV0, const TArray<FLinearColor>& VertexColors, const TArray<FProcMeshTangent>& Tangents);
If you have a <YourGameName>GameModeBase.cpp, make sure to add a reference to the header of the class where you added the above code, that way you will see it in your Editor in "C++ Classes" Content Browser and will be able to drag it to your scene.
Procedural Mesh Component in C++:Getting Started的更多相关文章
- UE4 Tutorial - Custom Mesh Component 用于绘制自定义网格的插件CustomMeshComponent
UE4 中用于绘制自定义网格的插件CustomMeshComponent. 转载: UE4 Tutorial - Custom Mesh Component Over the last few w ...
- [UE4]在Character中使用Add Spline Mesh Component,关于Transform.Mobility
一.因为Character是可移动的,因此也需要把Add Spline Mesh Component的Transform.Mobility设置为Movable 二.不然就会得到类似这样的提示.错误信息 ...
- Unreal Engine 4 动态切割模型实现
转自:http://gad.qq.com/article/detail/33199 <合金装备:复仇>里面,有一个很有趣的设定,游戏里大部分的场景和物件都可以用主角的刀动态切割. UE4中 ...
- [UE4]虚幻4 spline组件、spline mesh组件的用法
最近公司项目需要,把这两个东东好好看了下.不得不说,这两个组件还是非常方便的,但是相关的介绍.教程却非常的少.它们概念模糊,用法奇特,我就总结下吧. 首先,先要明白spline component.s ...
- UE4 在C++ 动态生成几何、BSP体、Brush ---- Mesh_Generation
截至UE4 4.10 runtime 无法生成BSP类 ,只能通过自定义的Mesh的Vertex 进行绘制 ( Google 考证,能改UE4源码的请忽略 ) 可用到的 UE4 集成的Render ...
- Unity Glossary
https://docs.unity3d.com/2018.4/Documentation/Manual/Glossary.html 2D terms 2D Physics terms AI term ...
- Unity3D引擎扩展中的编辑器定制方法
http://gamerboom.com/archives/36432 作者:Richard Fine Unity3D的方便之处在于,它很容易地扩展编辑器套件.每款游戏都对加工有着不同的需求,可以快速 ...
- 从Unity引擎过度到Unreal4引擎(最终版)
原文地址:http://demo.netfoucs.com/u011707076/article/details/44036839 前言 寒假回家到现在已经有十多天了,这些天回家不是睡就是吃....哎 ...
- [UE4]Grab抓取
一.关键函数:AttachToCompoent,将要抓取的物品附加到角色手上,让物品跟随手移动,开起来就像是抓取在手里了. 二.取消模拟物理.在开启模拟物理的情况下,AttachToCompoent是 ...
随机推荐
- 微信小程序~Flex布局
有一点需要注意的是,你的小程序要求兼容到iOS8以下版本,需要开启样式自动补全.开启样式自动补全,在“设置”—“项目设置”—勾选“上传代码时样式自动补全”.
- 状压dp之位运算
## 一.知识 1.我们知道计算机中数据由二进制数存储,一个二进制数的一位就是计算机中数据的最小单位bit,我们有一种运算符可直接对二进制数进行位运算,所以它的速度很快. 2.C++中的位运算符有6种 ...
- 异常检测(Anomaly detection): 什么是异常检测及其一些应用
异常检测的例子: 如飞机引擎的两个特征:产生热量与振动频率,我们有m个样本画在图中如上图的叉叉所示,这时来了一个新的样本(xtest),如果它落在上面,则表示它没有问题,如果它落在下面(如上图所示), ...
- Oracle中INSTR函数与SQL Server中CHARINDEX函数
Oracle中INSTR函数与SQL Server中CHARINDEX函数 1.ORACLE中的INSTR INSTR函数格式:INSTR(源字符串, 目标字符串, 起始位置, 匹配序号) 说明:返回 ...
- REdis之maxmemory解读
redis.conf中的maxmemory定义REdis可用最大物理内存,有多种书写方式,以下均为合法: maxmemory 1048576 maxmemory 1048576B maxmemory ...
- hhhhh我又双叒进步啦!
虽然说从今天开始短暂的暑假一周假期正式开始,然而第一天我就深感在家有多无聊...所以说还是整天待在学校好丫! 不过,就算在家, 勤奋好学的 我也要认真做题!今天就一鼓作气地把排名刷到了第 50 名!! ...
- mysql 表联结,内部联结
mysql> select * from user; +------+----------+-----------+ | id | name | address | +------+------ ...
- 「APIO2018」选圆圈
传送门 Description 有\(n\)个圆,每次找到这些圆中半径最大中的编号最小的圆,删除ta及与其有交集的所有圆. 对于每个圆,求出它是被哪一个圆删除的. Solution K-D Tree ...
- spring boot validation参数校验
对于任何一个应用而言在客户端做的数据有效性验证都不是安全有效的,这时候就要求我们在开发的时候在服务端也对数据的有效性进行验证. Spring Boot自身对数据在服务端的校验有一个比较好的支持,它能将 ...
- 刷题之给定一个整数数组 nums 和一个目标值 taget,请你在该数组中找出和为目标值的那 两个 整数
今天下午,看了一会github,想刷个题呢,就翻出来了刷点题提高自己的实际中的解决问题的能力,在面试的过程中,我们发现,其实很多时候,面试官 给我们的题,其实也是有一定的随机性的,所以我们要多刷更多的 ...