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是 ...
随机推荐
- Spring boot集成Swagger2,并配置多个扫描路径,添加swagger-ui-layer
Spring boot集成Swagger,并配置多个扫描路径 1:认识Swagger Swagger 是一个规范和完整的框架,用于生成.描述.调用和可视化 RESTful 风格的 Web 服务.总体目 ...
- 项目(一)--python3--爬虫实战
最近看了python3网络爬虫开发实战一书,内容全面,但不够深入:是入门的好书. 作者的gitbook电子版(缺少最后几章) python3网络爬虫实战完整版PDF(如百度网盘链接被屏蔽请联系我更新) ...
- python iter()函数迭代器
迭代器为类序列对象提供了一个类序列的接口.python的迭代无缝地支持序列对象,而且它还允许程序员迭代非序列类型,包括用户定义的对象.迭代器用起来很灵巧,你可以迭代不是序列但表现处序列行为的对象,例如 ...
- 服务端高并发分布式架构演进之路 转载,原文地址:https://segmentfault.com/a/1190000018626163
1. 概述 本文以淘宝作为例子,介绍从一百个到千万级并发情况下服务端的架构的演进过程,同时列举出每个演进阶段会遇到的相关技术,让大家对架构的演进有一个整体的认知,文章最后汇总了一些架构设计的原则. 特 ...
- MySQL 内连接、外连接、左连接、右连接、全连接……太多了
用两个表(a_table.b_table),关联字段a_table.a_id和b_table.b_id来演示一下MySQL的内连接.外连接( 左(外)连接.右(外)连接.全(外)连接). 主题:内连接 ...
- Python爬虫 | 多线程、多进程、协程
对于操作系统来说,一个任务就是一个进程(Process),比如打开一个浏览器就是启动一个浏览器进程,打开一个记事本就启动了一个记事本进程,打开两个记事本就启动了两个记事本进程,打开一个Word就启动了 ...
- Flutter 简介(事件、路由、异步请求)
1. 前言 Flutter是一个由谷歌开发的开源移动应用软件开发工具包,用于为Android和iOS开发应用,同时也将是Google Fuchsia下开发应用的主要工具.其官方编程语言为Dart. 同 ...
- P2340 奶牛会展 DP 背包
P2340 奶牛会展 DP \(n\)头牛,每头牛有智商\(s[i]\)情商\(f[i]\),问如何从中选择几头牛使得智商情商之和最大 且 情商之和.智商之和非负 \(n\le 400,-10^3\l ...
- 坑:jmeter部署AWS云服务器时出现连接超时Non HTTP response code: org.apache.http.conn.HttpHostConnectException
背景: jmeter脚本部署到云服务器(AWS EC2)公网上时,启动jmeter脚本运行了5个小时才运行完毕,后面发现脚本报错timeout(如图),找了很久不知道原因,后面进入脚本发现全部在报错. ...
- 用Visual Studio编写UDF的一点小技巧(自动补全宏函数、变量)
下载Visual Studio,安装VS 下载番茄助手(Visual Assist X),链接:www.wholetomato.com,然后安装番茄助手 打开VS