UStaticMesh幾何數據相關(UE5.2)

UStaticMesh相關類圖

8f663eb4989e48579fd3d47252243c43.png

?

UStaticMesh的數據構成

?

UStaticMesh的FStaticMeshSourceModel

UStaticMesh的Mesh幾何元數據來自于FStaticMeshSourceModel, 一級Lod就存在一個FStaticMeshSourceModel.?FStaticMeshSourceModel幾何數據大致包含以下幾類:

Vertex(點), VertexInstance(頂點), Edge(邊),? ?Triangle(三角形),? ?Polygon(多邊形)

總體上概念和Houdini的一些幾何概念相似,每種幾何元素都可以附帶屬性,比如點的“Position”, 頂點的“Normal,UV”等等。

下面介紹下如何獲取Mesh元數據和相關屬性

void AMyActor::TestMeshInfo() const
{if(!Mesh)return;// SourceModelconst TArray<FStaticMeshSourceModel>& SourceModels = Mesh->GetSourceModels();for(int32 Index = 0; Index < SourceModels.Num(); Index++){FMeshDescription* MeshDesc = Mesh->GetMeshDescription(Index);if(MeshDesc){const FVertexArray& VertexArray =  MeshDesc->Vertices();// TVertexAttributesRef<FVector3f> VertexPositions = MeshDesc->VertexAttributes().GetAttributesRef<FVector3f>(MeshAttribute::Vertex::Position);TVertexAttributesRef<FVector3f> VertexPositions = MeshDesc->GetVertexPositions();//loop vertex postionfor(const FVertexID VertexID : VertexArray.GetElementIDs()){FVector3f& Pos = VertexPositions[VertexID];}UE_LOG(LogTemp, Warning, TEXT("Vertex num = %d"), VertexArray.Num());//loop vertex instance attributeconst FVertexInstanceArray& VertexInstanceArray = MeshDesc->VertexInstances();TVertexInstanceAttributesRef<FVector4f> VertexInstanceColors = MeshDesc->VertexInstanceAttributes().GetAttributesRef<FVector4f>(MeshAttribute::VertexInstance::Color);for(const FVertexInstanceID VertxInstanceId : VertexInstanceArray.GetElementIDs()){}UE_LOG(LogTemp, Warning, TEXT("VertexInstanceArray num = %d"), VertexInstanceArray.Num());//loop vertex edge attributeconst FEdgeArray& EdgeArray = MeshDesc->Edges();TEdgeAttributesRef<bool> EdgeHardness = MeshDesc->EdgeAttributes().GetAttributesRef<bool>(MeshAttribute::Edge::IsHard);for (FEdgeID EdgeID : EdgeArray.GetElementIDs()){}UE_LOG(LogTemp, Warning, TEXT("EdgeArray num = %d"), EdgeArray.Num());// loop triangle attributeconst FTriangleArray& TriangleArray = MeshDesc->Triangles();TTriangleAttributesRef<FVector3f> TriangleNormals = MeshDesc->TriangleAttributes().GetAttributesRef<FVector3f>(MeshAttribute::Triangle::Normal);for (FTriangleID TriangleID : TriangleArray.GetElementIDs()){}UE_LOG(LogTemp, Warning, TEXT("TriangleArray num = %d"), TriangleArray.Num());// loop polygonconst FPolygonArray& PolygonArray =  MeshDesc->Polygons();TPolygonAttributesRef<int32> PatchGroups = MeshDesc->PolygonAttributes().GetAttributesRef<int32>(MeshAttribute::Polygon::PolygonGroupIndex);UE_LOG(LogTemp, Warning, TEXT("PolygonArray num = %d"), PolygonArray.Num());}if(Mesh->GetRenderData()->LODResources.Num() > Index){TArray<FVector3f> Vertexs;auto& LodResource = Mesh->GetRenderData()->LODResources[Index];int32 VertexNum = LodResource.GetNumVertices();for(int32 I = 0; I < VertexNum; I++){Vertexs.Add(LodResource.VertexBuffers.PositionVertexBuffer.VertexPosition(I));}int32 TriangleNum = LodResource.GetNumTriangles();TArray<uint32> Indexs;for(int32 I = 0; I < TriangleNum; I++){Indexs.Add(LodResource.IndexBuffer.GetIndex(I * 3 + 0));Indexs.Add(LodResource.IndexBuffer.GetIndex(I * 3 + 1));Indexs.Add(LodResource.IndexBuffer.GetIndex(I * 3 + 2));}}}
}

?

?

如何填充數據生成一個UStaticMesh

主要是通過填充FMeshDescription的各種圖元數據(Vertex, VertexInstance, Polygon, PolygonGroup等等)

void AMyActor::TestCreateStaticMesh()
{const FString ObjectName = "TestStaticMesh";const FString GameFoldPath = "/Game";const FString PackageName = FString::Printf(TEXT("%s/%s"), *GameFoldPath, *ObjectName);UPackage* Package = CreatePackage(*PackageName);UStaticMesh* MyMesh = NewObject<UStaticMesh>(Package, *ObjectName, RF_Standalone | RF_Public);FMeshDescription MeshDescription;FStaticMeshAttributes MeshAttribute(MeshDescription);MeshAttribute.Register();TArray<FDynamicMeshVertex> Vertices;Vertices.Add(FDynamicMeshVertex(FVector3f(500.0f, 500.0f, 200)));Vertices.Add(FDynamicMeshVertex(FVector3f(-500.0f, 500.0f, 200)));Vertices.Add(FDynamicMeshVertex(FVector3f(-500.0f, -500.0f, 200)));Vertices.Add(FDynamicMeshVertex(FVector3f(500.0f, -500.0f, 200)));TArray<int32> Indexs;Indexs.Add(0);Indexs.Add(3);Indexs.Add(1);Indexs.Add(1);Indexs.Add(3);Indexs.Add(2);MeshDescription.Empty();MeshDescription.ReserveNewVertices(Vertices.Num());MeshDescription.ReserveNewTriangles(Indexs.Num() / 3);MeshDescription.ReserveNewVertexInstances(Indexs.Num());TVertexAttributesRef<FVector3f> VertexPositions = MeshAttribute.GetVertexPositions();TVertexInstanceAttributesRef<FVector2f>	VertexInstanceUVs = MeshAttribute.GetVertexInstanceUVs();TVertexInstanceAttributesRef<FVector3f>	VertexInstanceNormals = MeshAttribute.GetVertexInstanceNormals();TVertexInstanceAttributesRef<FVector3f>	VertexInstanceTangents = MeshAttribute.GetVertexInstanceTangents();TPolygonGroupAttributesRef<FName> MaterialSlotNames = MeshAttribute.GetPolygonGroupMaterialSlotNames();TArray<UMaterialInterface*> MaterialInterfaces = {UMaterial::GetDefaultMaterial(MD_Surface)};for(int32 Index = 0; Index < MaterialInterfaces.Num(); Index++){FPolygonGroupID PolygonGroupID = MeshDescription.CreatePolygonGroup();FStaticMaterial StaticMaterial = MaterialInterfaces[Index];MaterialSlotNames[PolygonGroupID] = StaticMaterial.MaterialSlotName;}//create vertexfor(int32 Index = 0; Index < Vertices.Num(); Index++){FVertexID VertexId = MeshDescription.CreateVertex();VertexPositions.Set(VertexId, Vertices[Index].Position);}//create vertex instancefor(int32 Index = 0; Index < Indexs.Num(); Index++){FVertexInstanceID VertexInstanceId = FVertexInstanceID(Index);FVertexID VertexID = FVertexID(Indexs[Index]);MeshDescription.CreateVertexInstanceWithID(VertexInstanceId, VertexID);}// set vertex instance normal/tangent/uvFPolygonGroupID PolygonGroupID(0);TArray<FVertexInstanceID> InstanceIds;for(int32 Index = 0; Index < Indexs.Num(); Index++){FVertexInstanceID VertexInstanceId = FVertexInstanceID(Index);InstanceIds.Add(VertexInstanceId);const FDynamicMeshVertex& DynamicVertex = Vertices[Indexs[Index]];VertexInstanceUVs.Set(VertexInstanceId, DynamicVertex.TextureCoordinate[0]);VertexInstanceNormals.Set(VertexInstanceId, DynamicVertex.TangentX.ToFVector3f());VertexInstanceTangents.Set(VertexInstanceId, DynamicVertex.TangentZ.ToFVector3f());if(InstanceIds.Num() == 3){TArray<FEdgeID> EdgeIds;MeshDescription.CreatePolygon(PolygonGroupID, InstanceIds, &EdgeIds);InstanceIds.Empty();}}// create source model lod0 and commit mesh descconst int32 LodIndex = 0;if(!MyMesh->IsSourceModelValid(LodIndex)){FStaticMeshSourceModel& SourceModel = MyMesh->AddSourceModel();SourceModel.BuildSettings.bRecomputeNormals = false;SourceModel.BuildSettings.bRecomputeTangents = false;SourceModel.BuildSettings.bGenerateLightmapUVs = false;}MyMesh->CreateMeshDescription(LodIndex, MeshDescription);MyMesh->CommitMeshDescription(LodIndex);MyMesh->ImportVersion = EImportStaticMeshVersion::LastVersion;MyMesh->CreateBodySetup();MyMesh->GetBodySetup()->CollisionReponse = EBodyCollisionResponse::BodyCollision_Disabled;MyMesh->Build(true);MyMesh->PostEditChange();MyMesh->MarkPackageDirty();FAssetRegistryModule::AssetCreated(MyMesh);
}

4cf12657eaea4f30b908fbb25d410d6f.png

?

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/web/12464.shtml
繁體地址,請注明出處:http://hk.pswp.cn/web/12464.shtml
英文地址,請注明出處:http://en.pswp.cn/web/12464.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

【scikit-learn005】支持向量機(Support Vector Machines, SVM)ML模型實戰及經驗總結(更新中)

1.一直以來想寫下基于scikit-learn訓練AI算法的系列文章&#xff0c;作為較火的機器學習框架&#xff0c;也是日常項目開發中常用的一款工具&#xff0c;最近剛好擠時間梳理、總結下這塊兒的知識體系。 2.熟悉、梳理、總結下scikit-learn框架支持向量機&#xff08;Support Vec…

Maven(項目管理和LINUX)

目錄 一、整合IDEA 二、POM模型 三、依賴和繼承關系 依賴&#xff08;Dependency&#xff09; 依賴的基本結構 依賴傳遞性 依賴管理 繼承&#xff08;Inheritance&#xff09; 繼承的基本結構 繼承的特性 四、插件的使用 五、私服的使用 一、整合IDEA 在Maven項目…

基于springboot的醫院管理系統源碼數據庫

基于springboot的醫院管理系統源碼數據庫 隨著信息互聯網信息的飛速發展&#xff0c;醫院也在創建著屬于自己的管理系統。本文介紹了醫院管理系統的開發全過程。通過分析企業對于醫院管理系統的需求&#xff0c;創建了一個計算機管理醫院管理系統的方案。文章介紹了醫院管理系…

玩轉Matlab-Simscape(初級)- 06 - 基于Solidworks、Matlab Simulink、COMSOL的協同仿真(理論部分2)

** 玩轉Matlab-Simscape&#xff08;初級&#xff09;- 06 - 基于Solidworks、Matlab Simulink、COMSOL的協同仿真&#xff08;理論部分2&#xff09; ** 目錄 玩轉Matlab-Simscape&#xff08;初級&#xff09;- 06 - 基于Solidworks、Matlab Simulink、COMSOL的協同仿真&am…

風電功率預測 | 基于GRU門控循環單元的風電功率預測(附matlab完整源碼)

風電功率預測 風電功率預測 | 基于GRU門控循環單元的風電功率預測(附matlab完整源碼)完整代碼風電功率預測 | 基于GRU門控循環單元的風電功率預測(附matlab完整源碼) 完整代碼 clc; clear close allX = xlsread(風電場預測.xlsx)

python數據分析——seaborn繪圖2

參考資料&#xff1a;活用pandas庫 # 導入庫 import pandas as pd import matplotlib.pyplot as plt import seaborn as sns tipspd.read_csv(r"...\seaborn常用數據案例\tips.csv") print(tips.head()) 1、成對關系表示 當數據大部分是數據時&#xff0c;可以使用…

分享一個基于Qt的Ymodem的上位機(GitHub開源)

文章目錄 1.項目地址2.Ymodem 協議介紹3.文件傳輸過程4.使用5.SecureCRT 軟件也支持Ymodem6.基于PyQt5的Ymodem界面實現案例 1.項目地址 https://github.com/XinLiGH/SerialPortYmodem 基于VS2019 Qt5.15.2 編譯&#xff0c;Linux下編譯也可以&#xff0c;這里不做說明。 2.…

Python | Leetcode Python題解之第89題格雷編碼

題目&#xff1a; 題解&#xff1a; class Solution:def grayCode(self, n: int) -> List[int]:ans [0] * (1 << n)for i in range(1 << n):ans[i] (i >> 1) ^ ireturn ans

如何在云電腦實現虛擬應用—數據分層(應用分層)技術簡介

如何在云電腦實現虛擬應用—數據分層&#xff08;應用分層&#xff09;技術簡介 近幾年虛擬化市場實現了非常大的發展&#xff0c;桌面虛擬化在企業中應用越來越廣泛&#xff0c;其擁有的如下優點得到大量企業的青睞&#xff1a; 數據安全不落地。在虛擬化環境下面數據保存在…

STL庫簡介

一、STL庫的概念 STL&#xff1a;是C標準庫的重要追組成部分&#xff0c;不僅是一個可以復用的組件庫&#xff0c;而且還是一個包含了數據結構和算法的軟件框架。 二、STL的版本 原始版本 Alexander Stepanov、 Meng Lee 在惠普實驗室完成的原始版本&#xff0c; 是一個開源…

JVM 雙親委派機制詳解

文章目錄 1. 雙親委派機制2. 證明3. 優勢與劣勢 1. 雙親委派機制 類加載器用來把類加載到 Java 虛擬機中。從JDK1.2版本開始&#xff0c;類的加載過程采用雙親委派機制&#xff0c;這種機制能更好地保證 Java 平臺的安全。 1.定義 如果一個類加載器在接到加載類的請求時&…

react組件渲染性能優化之函數組件-useCallback使用

useCallback主要就是對函數進行緩存,useCallBack這個Hooks主要是解決React.memo不能緩存事件的問題 useCallBack(fn, dependencies) &#xff1a;fn想要緩存的函數&#xff0c;dependencies有關是否更新 fn 的所有響應式值的一個列表 比如&#xff1a;UseCallBackOptimize組件…

(done) NLP+HMM 協作,還有維特比算法

參考視頻&#xff1a;https://www.bilibili.com/video/BV1aP4y147gA/?p2&spm_id_frompageDriver&vd_source7a1a0bc74158c6993c7355c5490fc600 &#xff08;這實際上是 “序列標注任務”&#xff09; HMM 的訓練和預測如下圖 訓練過程&#xff1a;我們首先先給出一個語…

做一個桌面懸浮翻頁時鐘

毛玻璃效果翻頁桌面懸浮時鐘&#xff0c;TopMost&#xff08;Topmost“True”&#xff09;&#xff0c;不在任務欄顯示&#xff08;ShowInTaskbar“False”&#xff09;&#xff0c;在托盤區顯示圖標&#xff0c;雙擊托盤區圖標實現最小化和還原&#xff0c;右鍵托盤圖標可選“…

常見網絡攻擊及解決方案

網絡安全是開發中常常會遇到的情況&#xff0c;為什么會遇到網絡攻擊&#xff0c;網絡攻擊是如何進行的&#xff0c;如何抵御網絡攻擊&#xff0c;都是我們需要思考的問題。 為什么會遇到網絡攻擊&#xff1f; 以下是一些主要的因素&#xff1a; 技術漏洞&#xff1a;軟件或操…

web學習記錄--(5.14)

1.Sublime安裝與漢化 直接點擊windows即可下載&#xff0c;安裝即可 Thank You - Sublime Text 漢化 Install Package ChineseLocalzation 2.PHPstorm下載以及激活,漢化 直接下載&#xff0c;然后找激活碼激活即可 漢化 plugins&#xff08;插件&#xff09;/chinese&…

SpringBoot接收參數的19種方式

https://juejin.cn/post/7343243744479625267?share_token6D3AD82C-0404-47A7-949C-CA71F9BC9583

未授權訪問:ZooKeeper 未授權訪問漏洞

目錄 1、漏洞原理 2、環境搭建 3、未授權訪問 防御手段 今天繼續學習各種未授權訪問的知識和相關的實操實驗&#xff0c;一共有好多篇&#xff0c;內容主要是參考先知社區的一位大佬的關于未授權訪問的好文章&#xff0c;還有其他大佬總結好的文章&#xff1a; 這里附上大…

在Ubuntu中如何解壓zip壓縮包??

2024年5月15日&#xff0c;周三上午 使用 unzip 命令 unzip 文件名.zip這會將壓縮包中的內容解壓到當前目錄。如果想解壓到特定目錄&#xff0c;可以使用 -d 選項&#xff0c;例如&#xff1a; unzip 文件名.zip -d 目標目錄使用 7-zip 還可以安裝 7-zip 工具來解壓 ZIP 文件。…

【Python探索之旅】冒泡排序(三種方法)

前言 算法步驟&#xff1a; 代碼實現 方法一、嵌套循環 方法二 while循環 方法三、使用生成器表達式 解釋&#xff1a; 時間復雜度&#xff1a; 完結撒花 前言 冒泡排序是一種簡單的排序算法&#xff0c;它也是一種穩定排序算法。其實現原理是重復掃描待排序序列&#xf…