Hello everyone, I’m working on a game system that allow the player to transform certain object . Translataion, Rotation and Scale are pretty straighforward, but the tricky part is the player must be able to Shear and Reflect the object.
Beleive me, if I could avoid these transformations I would, but it’s a boss’s request .
Hey again Gamer08, moving over here since it will easier for other people to find relevant information. I’m currently at work and I’m not tasked with vertices manipulation so I’ll have to refresh my memory once I get home but have you checked out the FDynamicRHI::RHICreateVertexBuffer function?
If you have the vertex buffer you want then this should apply it to the mesh. According to the API you can even call it at runtime. Here’s an example (written by Epic in the 4.7 engine) of how to use it to create a unit cube:
class FUnitCubeVertexBuffer : public FVertexBuffer
{
public:
/**
* Initialize the RHI for this rendering resource
*/
void InitRHI() override
{
const int32 NumVerts = 8;
TResourceArray<FVector4, VERTEXBUFFER_ALIGNMENT> Verts;
Verts.SetNumUninitialized(NumVerts);
for (uint32 Z = 0; Z < 2; Z++)
{
for (uint32 Y = 0; Y < 2; Y++)
{
for (uint32 X = 0; X < 2; X++)
{
const FVector4 Vertex = FVector4(
(X ? -1 : 1),
(Y ? -1 : 1),
(Z ? -1 : 1),
1.0f
);
Verts[GetCubeVertexIndex(X, Y, Z)] = Vertex;
}
}
}
uint32 Size = Verts.GetResourceDataSize();
// Create vertex buffer. Fill buffer with initial data upon creation
FRHIResourceCreateInfo CreateInfo(&Verts);
VertexBufferRHI = RHICreateVertexBuffer(Size, BUF_Static, CreateInfo);
}
};
Thx for sharing the code. However, there is a problem which you can see from your screenshot: all the actor using the same static mesh is changed. Is there a way to only modify one actor’s mesh without change others?
Your answer is excellent!
But I want to ask a question. If I change the TResourceArray, would the VertexBufferRHI change accordingly?
And one more question, can it be done if I use the C float array not the TResourceArray to create the VertexBufferRHI?