Firstly, thanks to the guys developing this; it’s really helping me in my project. I also want to state that I am a complete novice, so the way I have implemented this is probably not the best.
[=cj31387;178518]
yeah I want to know if its possible to create meshes in the editor, so i can make my own super low poly old school terrain system, and make my own terrain brushes that move a vertex up or down. Like this…
The reason I’m asking is because I’ve read that dynamic collision doesn’t work yet in the editor.
[/]
I am doing the same thing and I hope my explanation is answering what you are asking. At first, I was just using one GeneratedMeshComponent to make the top layer. It contained a dynamic 2D array of FVector’s that contained the vertex locations for it and just looped through it making 2 triangles for each tile in the construction. I am currently reimplementing this using a Tile struct to allow each tile to be an individual block with 8 vertices each rather than a “plane” (think RollerCoater Tycoon type terrain, where each tile can be raised separately).
To start this project, I had used the Top-Down shooter project originally, and in there I picked up the code for cursor interactions: -
APlayerController* Controller = GetPlayerController();
if (Controller != NULL)
{
FHitResult Hit;
Controller->GetHitResultUnderCursor(ECC_Visibility, false, Hit);
if (Hit.bBlockingHit)
{
// We hit something
if (CursorHL != NULL)
{
CursorHL->UpdateLocation(Hit.ImpactPoint);
}
}
}
The Hit.ImpactPoint gives you an FVector of where in the world the cursor hit an object. In my code above, I am using another class, CursorHL, that contains a cursor object which highlights the relevant tile using another GeneratedMeshComponent as that allowed me to modify it to “follow” slopes. The function UpdateLocation takes those world co-ords and “snaps” them to the grid before moving the cursor. So far, I have only implemented the terrain and haven’t had any issues; it has always recognised the “collision” of the cursor with the GeneratedMeshComponent in the editor. I believe you can specify which objects you want to check the cursor has hit, which is going to be needed later when I start adding other things on top of the terrain and I only want to highlight the terrain.
To modify the terrain in real time was a bit clumsy and would appreciate feedback on a better way of doing it. In my example, you press the LMB to raise a point or RMB to lower the point and this would then update the vextex FVector in the array. I then go around the vertex redrawing each tile in turn by creating another 2 triangles with the updated vertex location, using some logic to work out which way the diagonal would go as that would affect the way the slope looked and worked. The relevant triangles in the Triangles array are updated with these new triangles. Finally, after the updating the Triangles array for each tile as needed, the way I found to update the mesh was to use the code: -
MapChunkMesh->SetGeneratedMeshTriangles(Triangles);
where MapChunkMesh is my GeneratedMeshComponent.
Of course, when you have a large map, you don’t want to redraw the whole thing each time, so I broke it down into “chunks”. This also seemed to help performance and at the moment, I am finding 32 x 32 to be a good spot and I don’t think my maps will go above 1024 x 1024 at the moment. Once I’ve settled on a chunk size, I can probably get rid of the dynamic part of the 2D array within each chunk. I still have a dynamic 2D array of these chunks, each of which is a GeneratedMeshComponent, to allow for custom map sizes.
I hope that goes some way to answer your question, assuming I understood it correctly!