Search Unity

Uniblocks: cube-based infinite voxel terrain engine

Discussion in 'Assets and Asset Store' started by RawLionWorkshop, Feb 2, 2014.

  1. Firlefanz73

    Firlefanz73

    Joined:
    Apr 2, 2015
    Posts:
    1,316
    My idea:
    Add a (invisble) voxel with no mesh or something like that.
    Put it to the neightbor Position and set collision to cube. This mesh has the same voxel Events like the one you want.

    Or if you have more like that: The invisble voxel gets new voxelevents. These look all their neighbors, if they are "Special" voxels and then call their voxel Events.

    Something like that. If you have a better idea let me know :)
     
  2. arturnik17

    arturnik17

    Joined:
    Dec 13, 2017
    Posts:
    19
    Worked like a charm! a bit messy when you have a few rotations of the block but there is no ideal solution.
    Check your game thread, seems like the download link is down.
     
  3. MortyKid

    MortyKid

    Joined:
    Jul 2, 2018
    Posts:
    4
    Just realized that Uniblocks is down too, Anyone left here who is active? I'm trying to add water but I don't know how to allow it to flow since every block combines to a big mesh and you cant add scripts to blocks.
    Anyone here who added water and can guide me to the right direction?
     
  4. Firlefanz73

    Firlefanz73

    Joined:
    Apr 2, 2015
    Posts:
    1,316
    I made 10 cube blocks with different height call them waterblocks.
    When neighbor or under block is empty, it becomes the flat waterblock (or the next one a bit less flat), and the waterblock itself gets the next lower block. You can do something like this in the chunk update method.It is simple but works. They have no collider and a transparent blue texture and you can even use a water shader from the Standard assets to animate or something from the store.

    I did the same for Lava and poisoned green water too :)

    If you like to, you can download and play my game (I made with uniblocks) here, you will quickly find water when moving around:

    https://forum.unity.com/threads/bio...-free-and-gimme-feedback.509243/#post-3541717
     
  5. arturnik17

    arturnik17

    Joined:
    Dec 13, 2017
    Posts:
    19
    Thanks for the advice but I have to ask how do you find that there is a water source block in that chunk because going through every block to check sounds not efficient.
    Unless you meant that when rebuilding mesh in a chunk I should keep an eye out for water source blocks, save it in a list along side the rest of the water source blocks and when there is a change in the map check accordingly if water update is needed?
    Thank you for the quick reply, I will have a look at your game, I'm interested in seeing how it works.
     
  6. Firlefanz73

    Firlefanz73

    Joined:
    Apr 2, 2015
    Posts:
    1,316
    Yes, I am doing a Chunk update from time to time for all chunks around the Player.
    This way I am having slowly flowing water, but also growth etc, for example a mud voxel becomes a gras voxel when there is empty space above it, seedlings grow to trees etc.
    I tried to get it working with Multitasking and I failed.
    But if you do not update all chunks at once, Always one or two nearby chunks each second, it works good for me.
     
  7. MortyKid

    MortyKid

    Joined:
    Jul 2, 2018
    Posts:
    4
    Thanks for the idea, I am almost done with the water but I've encountered two weird problems.
    The first one is that there are 4 (0,0,0) chunk index. which is weird because I thought that the chunk index should be unique. (it makes using chunk indexes unpredictable..) anyone else who has this problem?
    The second one is a bit different, I just cant find a way to animate voxels, I am using a shader with waves for the water voxels and it works without the animation of the waves.
     
  8. MortyKid

    MortyKid

    Joined:
    Jul 2, 2018
    Posts:
    4
    Anyone?
     
  9. Firlefanz73

    Firlefanz73

    Joined:
    Apr 2, 2015
    Posts:
    1,316
    I guess the 4 chunks with 0,0,0 may be an error / exception?
    Maybe you could add a try .. catch (Exception ex) Debug.LogError(… + ex)
    to the part(s) of the source, where the initializing and positioning of a chunk happens, run in Unity Editor and try to find the error in the console :)

    for me animated water with a shader works perfect. I guess there is something wrong with the shader?
    There are water shaders included in the Standard assets of Unity with Animation. And several on the asset store.
     
  10. MortyKid

    MortyKid

    Joined:
    Jul 2, 2018
    Posts:
    4
    It is not an error, that is the weird part. I had to change it manually in the PositionToChunk functions because when you get a position of a block that is x = -5 in world cords it would return the (0,0,0) chunk since you are dividing -5 by 16.
    Unless I changed something a while back by mistake it was coded that way.

    You are completely right about the water lol, chose the wrong material xD

    Thanks for the help!
     
  11. arturnik17

    arturnik17

    Joined:
    Dec 13, 2017
    Posts:
    19
    After using Unity 2018 for a while I found out that they brought back the 65,535 vertices limit per mesh.
    So unlike in Unity 2017.3 you have to be very careful with any additional meshes you add to a chunk, having more then 65,535 vertices per chunk will 'corrupt' it.
    It's something important to take into consideration when upgrading to Unity 2018.
     
  12. Firlefanz73

    Firlefanz73

    Joined:
    Apr 2, 2015
    Posts:
    1,316
    I thought this Limit was for all Unity versions?
    When I spawn too much into an area / chunk I always get an exception and a large "hole" in that chunk.
    How do I get rid of that Limit with Unity 2017?

    Thanks for the info!
     
  13. arturnik17

    arturnik17

    Joined:
    Dec 13, 2017
    Posts:
    19
    Found out about it because of the same large "hole" in that chunk.
    So, the way Uniblocks was designed to work before Unity 2017.3 was by simply creating a mesh container within the Chunk once it's exceeds the vertices limit.
    In Unity 2017.3 they have added support for 32 bit mesh buffers, which supports up to 4 billion vertices I think.
    I am still trying to figure it out but my initial comment about it was wrong, Unity 2017.3+ supports more then 65k vertices.(including Unity 2018).
    You will have to upgrade to Unity 2017.3 at the very least to have this feature, since I am on Unity 2018 at the moment I will try and change the code to support it instead of using the previous method. (creating additional mesh containers).
    I will let you know tomorrow of any progress!

    Update: All you have to do to increase the vertices limit is to change in the ChunkMeshCreator script those lines.
    (works on Unity 2017.3+)
    if (Vertices.Count + mesh.vertices.Length > 65534)
    { -> changed it to 60,000 to be sure. (size it according to your biggest mesh)
    CreateNewMeshObject(); -> to GetComponent<MeshFilter>().mesh.indexFormat = UnityEngine.Rendering.IndexFormat.UInt32;
    }

    if (Vertices.Count > 65530) { - again changed to 60,000
    CreateNewMeshObject(); -> to GetComponent<MeshFilter>().mesh.indexFormat = UnityEngine.Rendering.IndexFormat.UInt32;
    }
     
    Last edited: Jul 30, 2018
  14. Firlefanz73

    Firlefanz73

    Joined:
    Apr 2, 2015
    Posts:
    1,316
    I am on Unity 2017.4.8. This would be really interesting, I removed some nice features from my landscape so that limit is not reached.

    There was something in the original code that should add a second chunk on the same Position (if more than 65k Vertices) but that never worked for me so I removed that.
     
  15. arturnik17

    arturnik17

    Joined:
    Dec 13, 2017
    Posts:
    19
    Posted the change that fixed it for me, all you have to do is to change the indexFormat to 32 bit.
    It might be better to change it once when the chunk is instantiated instead of changing it everytime it's higher then 60,000.
     
    Firlefanz73 likes this.
  16. Firlefanz73

    Firlefanz73

    Joined:
    Apr 2, 2015
    Posts:
    1,316
    Thanks a lot for the info, I will try tomorrow :)

    Did you realize any disadvantage, maybe the saved chunks got larger in Memory or something?
     
  17. arturnik17

    arturnik17

    Joined:
    Dec 13, 2017
    Posts:
    19
    I would assume it will take more memory and the bandwidth as it's measured in bit/s.
    It might be worth it to keep the lower vertice chunks with the limit and change it as it goes.

    Keep in mind that you have to be careful with it as not all platforms seem to work with it.(some iOS, Android devices..)

    Haven't played with it at all yet but tomorrow I will try to make it as efficient as possible! :)
     
  18. quanhulee

    quanhulee

    Joined:
    Nov 20, 2018
    Posts:
    4
    I want to find a way to build voxel in some certain area,and each area can be tuned individually but stored as one world file.
    sorry,i am not a programmer, if anyone have good idea to solve this, reply me,tks.
     
  19. AldeRoberge

    AldeRoberge

    Joined:
    Jun 23, 2017
    Posts:
    60
    Is this project 100% dead? Maybe consider hosting the source on GitHub... : ]