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是 ...
随机推荐
- 压缩及解压命令gzip、bzip2、tar
1. gzip 描述:压缩与解压缩 用法:gzip[选项]...[文件名称]... 选项:-d 解压 gzip hello.txt # 文件压缩后名为hello.txt.gz gzip -d ...
- netstat -an unix socket 会阻塞吗
[lyd@localhost ~]$ netstat -an | grep "SOFO"unix 2 [ ACC ] SEQPACKET LISTENING 86308 @*MY- ...
- 查询响应慢,DB近乎崩溃
时间:18.11.22 一. 起由: 公司最近因业务,有大量注册,每天大约几万,貌似也不太高? 晚上8点左右,网站后台,前台突然大面积提示502.网站几乎瘫痪.买的阿里云的负载均衡和读写分离.分别是5 ...
- C++ vector,list,deque区别(转)
在写C++程序的时候会发现STL是一个不错的东西,减少了代码量,使代码的复用率大大提高,减轻了程序猿的负担.还有一个就是容器,你会发现要是自己写一个链表.队列,或者是数组的时候,既要花时间还要操心 ...
- python的多线程是否没有用了
python的多线程是否就完全没有用了呢? 相同的代码,为何有时候多线程会比单线程慢,有时又会比单线程快? 这主要跟运行的代码有关: 1. CPU密集型代码 (各种循环处理.计数等等 ),在这种情况下 ...
- Python 3的 bytes 数据类型
"""b'\xe6\x88\x91\xe7\x88\xb1Python\xe7\xbc\x96\xe7\xa8\x8b'代表这是一个字节窜,\x代表十六进制表示 e6是十 ...
- web大附件上传,支持断点续传
一. 功能性需求与非功能性需求 要求操作便利,一次选择多个文件和文件夹进行上传:支持PC端全平台操作系统,Windows,Linux,Mac 支持文件和文件夹的批量下载,断点续传.刷新页面后继续传输. ...
- BZOJ 1034: [ZJOI2008]泡泡堂BNB 贪心+排序
比较神奇的贪心 有点类似于田忌赛马. 如果我方最弱强于对面最弱,则直接最弱pk最弱. 如果我方最强强于对面最强,那么直接最强间pk. 否则,试着用我方最弱 pk 对方最强,看是否能打成平手. code ...
- learning scala akka ask_pattern
package com.example import akka.actor._ import akka.util.Timeout object Tutorial_03_Ask_Pattern exte ...
- hhhhh臭不要脸//捂脸)多不好意思啊you进步惹
如题↑↑↑ 千万不要相信题目 还是看图说话吧↓↓↓ 我真的蒟蒻啊,,,准确率在70边缘徘徊,卑微☹ 不过还是侥幸地进入了前 30 名! 今天七夕欸,然鹅,,, qq空间里面弥漫着恋爱的酸臭味 香气,‘ ...