Dynamic terrain deformation during the game?

0

I work in Unity and look at Lumberyard with curiosity. I need the ability to deform the terrain in real time during the game. I mean only the change in the height of the ground's vertexes: craters from explosions, dynamic track from the wheels, etc.

Is this possible in a Luberyard?

How much is this solution ready to work out of the box?

Thanks in advance for the answer!

preguntada hace 5 años261 visualizaciones
9 Respuestas
0

Yes, you can change Terrain during runtime with using this

gEnv->p3DEngine->GetITerrain()->SetTerrainElevation (...)

Here is short demo GIF

respondido hace 5 años
0

Are there any documents for this? I could not find anything.

respondido hace 5 años
0

Yeah, there is no any docs about this feature, but since it's just legacy cryengine tech you could find some examples/code of using terrain SetTerrainElevation on their old forum.

I wrote TerraformingComponent for terrain test, it's very raw, but since there is no info about this, you could take a look on it, how it works

TerraformingBus.h

TerraformingComponent.h

TerraformingComponent.cpp

typical situation I add this component on some entity and then use EBus to change terrain

	else if (channelId == InputDeviceMouse::Button::Right)
{
GatherAroundHit();
TerraformingBus::Broadcast(&TerraformingBus::Events::UpdateTerrainCutout, m_hitPosition, m_gatherRadius, true);
}
respondido hace 5 años
0

Thanks for sharing.

respondido hace 5 años
0

I thought about it. How to implement what happens on gif means script canvas? Any ideas?

respondido hace 4 años
0

@REDACTEDUSER

respondido hace 4 años
0

It's been a while and you need to learn how to do it with the script canvas

respondido hace 4 años
0

The examples in this post that use CTerrain::SetTerrainElevation show the only way to do it at runtime currently (or in more recent versions, through LegacyTerrain::LegacyTerrainDataRequests::SetTerrainElevationAndSurfaceWeights). The terrain system as a whole is designed for edit-time modifications with a static unchanging terrain at runtime. As you've seen, it can be done, it's just not an exposed or documented feature. SetTerrainElevation enables the height and surface types to be changed, but just as a warning it's an extremely expensive operation, as it also adjusts roads, physics, vegetation, etc.

This call isn't exposed through Script Canvas, but if you wanted to add it, I think you'd want to do it by adding a Behavior Context to the LegacyTerrainLevelComponent and exposing one or more pass-through functions with whatever API you desire. SetTerrainElevation takes in the entire set of heights and surface weights - depending on your needs, you might want to break it up into an API to start modifications, one to take individual heights and/or weights at positions, and then one to commit the changes all at once.

Since you mention craters / explosions, you might also need to modify the terrain macro color, not just heights and weights. If you do, things get a bit more difficult. Look at CTerrainGrid::LockTerrainSector / UnlockTerrainSector to see how this works in the Editor. Basically, you'll need to create a new texture with the desired color changes baked into it, push it to video memory, and change which texture the relevant terrain sectors point to. For simplicity, I'd suggest just trying to manipulate it through the surface weights. :)

One last note - for wheel tracks, you might want to use decals and just "trick" the height deformation via normal maps, POM, or other techniques as opposed to adjusting the ground vertices. You'll get much better resolution and performance. It would just be a rendering effect, so it wouldn't affect physics or anything else, but in many cases that's really all you need for a game.

respondido hace 4 años
0

I really don't think something like this should/could be done via any visual scripting language.

Things like this should be done via C++ or shader code directly. (Because like @REDACTEDUSER

[quote="mikeb, post:9, topic:6314"] just as a warning it’s an extremely expensive operation [/quote]

which is already true if you code this in C++.

respondido hace 3 años

Está publicación está cerrada: la opción de añadir nuevas respuestas, comentarios y votos está deshabilitada.