VoxelPlugin / VoxelPluginFreeLegacy

Voxel Plugin Legacy for Unreal Engine
https://voxelplugin.com
1.56k stars 297 forks source link

Importing heightmaps at runtime #74

Open Phyronnaz opened 4 years ago

Phyronnaz commented 4 years ago

Hello, Could it be possible to import heightmaps at runtime ? Thanks :-) Cedric

SmallLemur commented 4 years ago

+1 this would be very useful for some projects Thanks !

chaiyuntian commented 4 years ago

Hi @Phyronnaz
Could you give us some clue on the best practice to implement this? We are going to implement this in our project.

Phyronnaz commented 4 years ago

Assuming you are using the RGB material config (other configs are similar), and that you loaded the image using the unreal ImageWrapper stuff already into TextureData:

auto* HeightmapAsset = NewObject<UVoxelHeightmapAssetUINT16>();
auto& HeightmapData = HeightmapAsset->GetData();

HeightmapData.SetSize(Width, Height, true, EVoxelMaterialConfig::RGB);

for (int32 X = 0; X < Width; X++)
{
    for (int32 Y = 0; Y < Height; Y++)
    {
            const int32 Index = X + Width * Y;
            HeightmapData.SetHeight(X, Y, TextureData[Index])
            HeightmapData.SetMaterial_RGB(X, Y, MyColor);
        }
}

Then use HeightmapAsset as world generator object. Let me know if you need more info @chaiyuntian

chaiyuntian commented 4 years ago

@Phyronnaz Thank you so much! I will try it.