Comments (4)
Well if you built the mesh section manually you should definitely already know the tris, vertices, normals, UVs and vertex colors. If you created the section from one of the procedural methods of RMC then the outputs of the relevant parameters will tell you exactly what you want:
TArray<FVector> Vertices;
TArray<int32> Triangles;
TArray<FVector> Normals;
TArray<FVector2D> TextureCoords;
TArray<FRuntimeMeshTangent> Tangents;
URuntimeMeshLibrary::CreateBoxMesh(FVector(Size, Size, Size), Vertices, Triangles, Normals, TextureCoordinates, Tangents);
Where Vertices
will be an array of vertex positions, Triangles
will be an array of each vertex index in winding order, Normals
will be an array of each triangle's normal in order and so on. With that you can determine that with this code:
int32 TriangleIndex;
TArray<FVector> TriangleVertices;
Triangle.Add(Vertices[Triangles[TriangleIndex * 3 + 0]]);
Triangle.Add(Vertices[Triangles[TriangleIndex * 3 + 1]]);
Triangle.Add(Vertices[Triangles[TriangleIndex * 3 + 2]]);
TriangleVertices
will contain all 3 vertex positions of the triangle at TriangleIndex
in winding order.
Also: knowing just the vertices and the indices you can get tris, normals, etc. Here's an accurate example of how to calculate the normals of a triangle index:
FVector CalculateTriangleNormal(int32 TriangleIndex)
{
int32 VertOffset = TriangleIndex * 3;
FVector Cross = FVector::CrossProduct(
Vertices[Triangles[VertOffset + 2]] - Vertices[Triangles[VertOffset + 0]], // Edge 1
Vertices[Triangles[VertOffset + 1]] - Vertices[Triangles[VertOffset + 0]]); // Edge 2
Cross.Normalize();
return Cross;
}
I think you need to read this Wiki entry: Mesh Basics. I also recommend doing more research on 3D geometry to better understand how just knowing the vertex positions and windings can get you triangles, the normals of those triangles, tangents, etc.
PS: RMC is fucking awesome @Koderz, thanks for your hard work!
from realtimemeshcomponent.
Fair enough, thanks for the info @Zinglish
How would I get the Vertex Buffer info for a mesh? Although I created the mesh I dont want to hold all these values as I assume the RuntimeMeshComponent would. I just need a way to access the Vertex buffer whenever I need. Is it exposed?
from realtimemeshcomponent.
Again, you should do some more research and reading before opening an issue to talk about information that's readily available. There's examples on how to use RMC, in the Animated Terrain Demo you can see how to grab and use the vertex buffer. Regardless I will, for the sake of anyone who's stuck on this, provide a minimal approach below.
If you create a mesh doing something like
TArray<FRuntimeMeshVertexNoPosition> VertexData;
FBox BoundingBox = FBox(FVector(Size, Size, Size), FVector(-Size, -Size, -Size));
URuntimeMeshLibrary::CreateBoxMesh(FVector(Size, Size, Size), Vertices, Triangles, Normals, TextureCoordinates, Tangents);
for(int32 i = 0; i < Normals.Num(); i++)
VertexData.Add(FRuntimeMeshVertexNoPosition(Normals[i], Tangents[i], TextureCoordinates[i]));
RMC->CreateMeshSectionDualBuffer(0, Vertices, VertexData, Triangles, BoundingBox, true, EUpdateFrequency::Frequent);
You can later get the vertex buffer with the following method
TArray<FVector>& Vertices = *RMC->BeginMeshSectionPositionUpdate(0);
You would then modify and vertices in the Vertices
array then call RMC->EndMeshSectionPositionUpdate(0);
which will force RMC to update the vertices in the UE4 renderer.
Do note that adding or removing any verts from the array returned from BeginMeshSectionPositionUpdate()
will likely result in a crash or unexpected behaviour. If you wish to add or remove verts from your mesh, I believe you will need to rebuild it entirely, discarding all previous information about the mesh, I haven't experimented with this myself all that much tbh.
from realtimemeshcomponent.
I have no intention of updating an exisiting mesh so I really don't think using BeginMeshSectionPositionUpdate(0)
is correct. It doesn't seem like it was meant to just get a reference.
Anyway, this worked for me -
const IRuntimeMeshVerticesBuilder* runtimeVertices;
const FRuntimeMeshIndicesBuilder* runtimeIndices;
Mesh->GetSectionMesh(0, runtimeVertices, runtimeIndices);
runtimeVertices now contains all vertex related data.
Thanks for your help @Zinglish.
from realtimemeshcomponent.
Related Issues (20)
- Fatal error: [File:D:/UE4_SRC/Engine/Source/Runtime/Windows/D3D11RHI/Private/D3D11Util.cpp] [Line: 198] Unreal Engine is exiting due to D3D device being lost. (Error: 0x887A0006 - 'HUNG') HOT 2
- Unhandled Exception: EXCEPTION_ACCESS_VIOLATION reading address 0xffffffffffffffff HOT 5
- Intermittent crash due to UE5 DX12 GPU memory bug HOT 6
- Fails to compile on UE5.2: error C2665: 'GetTypeHash': none of the 5 overloads could convert all the argument types HOT 2
- vram not enough HOT 2
- 5.1 crash (RayTracingGeometry->Initializer.TotalPrimitiveCount) HOT 5
- Intermittent link errors on UE 5.2 HOT 2
- RMC not visible in HTML5 HOT 1
- Just echoing question - 5.3 support planned? Thank you! HOT 2
- UE5.3 Packaging failed HOT 1
- Multiple UVs and High Precision UVs don't work HOT 1
- Create a basic mesh in Unreal 5.3 HOT 9
- RealtimeMeshAlgo::GenerateTangents type mismatch fixes HOT 1
- UpdateSectionGroup fix HOT 1
- Incorrect face index from trace
- Current version does not compile HOT 1
- Compilation fails on UE 5.3.2 due to function deprecation HOT 2
- Scale is not correct during mesh creation HOT 3
- Old samples in new plugin?
- How To replicate the runtimemesh on server HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from realtimemeshcomponent.