Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

After playing minecraft...

Discussion in 'General Discussion' started by jc_lvngstn, Oct 8, 2010.

Thread Status:
Not open for further replies.
  1. Enka2012

    Enka2012

    Joined:
    May 2, 2013
    Posts:
    8
    Thank you. Where can I find references about that?
     
  2. Foam

    Foam

    Joined:
    Jun 13, 2012
    Posts:
    322
    It is infinitely easier to just make simplified meshes for physics purposes and use Unity physics than to handle your own collisions. Simplified meshes are quite fast and the code for it is pretty straight-forward.
     
  3. Enka2012

    Enka2012

    Joined:
    May 2, 2013
    Posts:
    8
    Yeah, but actually I don't understand how to code simplified meshes. Could someone explain?
     
  4. Atanvaryar

    Atanvaryar

    Joined:
    Sep 1, 2012
    Posts:
    9
    Hi guys! I've been reading through all the thread and got plenty of awesome guidance and information for my experiments with voxels.
    I have a working engine based on 3d-arrays containing blocks in each chunk. What I want to try out now is the 1d array for the whole world that Alexzzz has made in his engine.
    I have managed to set that up too, but now I cannot seem to wrap my mind around actually assigning data from that array to individual chunks and then displaying it.
    Should I just calculate the pointer based on the chunk position or is there some other way?
     
  5. Foam

    Foam

    Joined:
    Jun 13, 2012
    Posts:
    322
  6. RSH1

    RSH1

    Joined:
    Jul 9, 2012
    Posts:
    255
  7. Atanvaryar

    Atanvaryar

    Joined:
    Sep 1, 2012
    Posts:
    9
    Hi everyone!
    I've been tampring some more with my voxel engine. I've implemented the 1D array for storing world data, and also put up a small event-driven system for my chunks. It works along these lines:
    I instantiate chunk placeholders and a chunk manager.
    Upon creation each chunk subscribes the chunkmanager to the created chunk.
    When all chunks are instantiated I iterate through all of them and subscribe them to their neighbours.
    Meanwhile, each chunk that the chunkmanager subscribes to it sends to the threaded queue for terrain generation.
    When all neighbours fire an event saying that their terrain is ready, the central chunk then fires an event to my chunkmanager, saying that (this) chunk is ready for mesh construction. The chunk manager then sends the chunk to a threaded queue for mesh generation with a high priority.
    This lets me display completed chunks with a mesh on screen even before all of them get their terrain generated.

    The system I have set up looks kinda like a state machine, but it's not. The chunks don't have any states, they just fire off events when something happens, in particular, when a method interacting with the chunk fires an event in that chunk. My threaded job fires a "terrain ready" event from within the chunk when the noise is finished generating and all values are assigned.

    So my current dilemma is this. Should I keep it as it is or should I try implementing full state machines for my chunks?
    I am a little bit concerned about performance. As far a I understand state machines are run every frame, and if I have hundreds of chunks, that's a lot of state machines runnning at the same time chewing away at the main thread performance. The events on the other hand don't use up resources at all. They just hand there waiting for someone to call them and then act. It's basicaly calling a method on another object. But then, events lack any kind of self-control. In a state you can make the chunk check for example if it has terrain every few seconds and if it doesnt (the thread bugged out for some reason or something like that), then send itself to the queue for another try and again and again, until the terrain generates successfully. I can't think of a way to do that using ust events.

    So what's your opinion on this?
     
  8. PhobicGunner

    PhobicGunner

    Joined:
    Jun 28, 2011
    Posts:
    1,813
    My advice is measure, measure, measure, before you go refactoring ANYTHING.
    You don't yet know if it's going to be bad performance wise. So test it!
     
  9. justin35f

    justin35f

    Joined:
    Jan 19, 2013
    Posts:
    37
    TL;DR
    Has anyone implemented unit based movement in a voxel game? Specifically looking for advice/ideas for determining how to make AI controlled units jump up blocks.

    Hey everyone, I haven't posted here in a little while, but I'm still working on my voxel game. I've taken a break from development because a few people joined my project turning it from a solo project to one with a small team. Anyways, it is going to be a city building game (think Stonehearth, Timber Stone, or Banished).

    So, I have voxel terrain working very well for what we want (so far...) and it is performing pretty well. Now this may be a little stretch for this thread, but I was wondering if anyone has done any kind of unit movement in a voxel world. Basically, this game has the player controlling several units (similar to an RTS) rather than a single player unit. Now in a typical game in which the player controls just the one unit, you have a finer degree of control for movement, you press buttons to move/jump. Well, with multiple Units, that's a bit too much micromanagement, so you usually just select the unit, then click where you want them to move (I'm not concerned about pathfinding right now).

    The issue is determining how to actually move, primarily, how to jump up/over blocks.


    Thanks!

    Latest video - it's a bit outdated, and I'm no longer using this LOD as it was, quite honestly, crap
     
  10. MrEsquire

    MrEsquire

    Joined:
    Nov 5, 2013
    Posts:
    2,712
    Hi all,

    Is there a way of making the whole game world more blocky looking?
    What aspect controls the looks of the blocks etc?
    Thanks
     
  11. goldbug

    goldbug

    Joined:
    Oct 12, 2011
    Posts:
    766
    Of course, make your terrain in the shape of blocks. Pretty much this entire thread discusses details on how to do it.

    Shader, textures, geometry, all determine how your blocks look.


    Perhaps I am misunderstanding the question.
     
  12. PhobicGunner

    PhobicGunner

    Joined:
    Jun 28, 2011
    Posts:
    1,813
    But, how do you make the blocks.... look more blocky!?

    I kid, I kid...
     
  13. MrEsquire

    MrEsquire

    Joined:
    Nov 5, 2013
    Posts:
    2,712
    Thanks dude, I been working of a project file some developers made for me long time ago.
    So I forgotten how they made this all, oldskool way.

    Currently we seem to be using MinePackage scripts to generate the world.
    I think its to simple and need something more complex but was wondering if there any scripts out there where I can do a simple copy and paste job for it to generate a random terrain with different hights and maybe caves?

    Any ideas how to proceed?

    Thank you
     
    Last edited: Apr 8, 2014
  14. goldbug

    goldbug

    Joined:
    Oct 12, 2011
    Posts:
    766
    Take a look at this page:
    http://unitycoder.com/blog/2012/10/18/voxel-resources-engines-for-unity/

    it list several free and commercial packages for block based terrain, it also has links to several tutorials (including mine :) ). Hopefully one of those packages provides what you are looking for.
     
  15. jordantotty

    jordantotty

    Joined:
    Dec 15, 2011
    Posts:
    77
    Hey guys! What do you think? :)
     

    Attached Files:

  16. MrEsquire

    MrEsquire

    Joined:
    Nov 5, 2013
    Posts:
    2,712
    Hey dude, thats amazing, how did u manage to do that?
    Is it mobile friendly?
     
  17. Vanamerax

    Vanamerax

    Joined:
    Jan 12, 2012
    Posts:
    938
    That looks great! How are you combining your perlin/simplex noises? are you using 2D or 3D noise or a combination of them? Btw, do you have biomes and if so, how do you calculate those?
     
  18. justin35f

    justin35f

    Joined:
    Jan 19, 2013
    Posts:
    37
    Hey guys, haven't posted in here for a few days. I've started trying to work out unit movement again. The difficulties I had stemmed from having units navigate around in a voxel world (cubes, no slopes). Right now I am doing a rigidbody.sweeptest() and 'jumping' if a collision would occur. I'm currently working out an FSM to determine what action the unit should take. I'll post some screenshots, or even a video later if I get something worthwhile worked out. Also, here is the latest video, showcasing the beginnings of biomes in my game world.

    Thanks!

     
  19. jordantotty

    jordantotty

    Joined:
    Dec 15, 2011
    Posts:
    77
    Thanks bro, and yep it's coming to mobile soon ;)
     
  20. jordantotty

    jordantotty

    Joined:
    Dec 15, 2011
    Posts:
    77
    I have like 7 different simplex noises 3D and 2D and I kinda played around with them untill it looked good :p
    And for biomes I used the "Bukkit" method (Go back a couple pages where I linked to the thread)
     
  21. Badreend

    Badreend

    Joined:
    Apr 15, 2014
    Posts:
    2
    Hi,

    Im working on my first game in Unity and so far Unity is damn great! But I need to optimize my foundation of the game. It seems that Unity does a lot of work already for me. Such as the Frustum Culling. But that is not what i need, because the game has to show 10.000 cubes each frame. I've placed down a video of a simple prototype. The prototype has one array filled with 10.000 cubes at the start. Everytime on the update its checking if each voxel is close enough to the player to become big. As your eyes will tell you, frustum culling is doing his job well if im close to the edges, you see like 1000-3000 cubes the fps is going up. If im on the center of the stage the fps is goind down beceause my camera is rendering each of those 9000 cubes.
    I've changed the mesh with a sphere and quad and still the cube is the fastest.

    I read a bit about, occlusionCulling, voxels, chuncking. But those articles are more specific to 3D positioning of voxels. In my situation I dont have things behind my stage. My goal is to have roughly 15k voxels with 60fps. So I know that it will run on lower specs.


    Is it possible to have that many on screen?
    And how?

    https://www.youtube.com/watch?v=NGx5zqA3RSM
     
  22. PhobicGunner

    PhobicGunner

    Joined:
    Jun 28, 2011
    Posts:
    1,813
    Unfortunately you're going about things all wrong. Each voxel cannot be an individual object - it gets very slow, very quickly.
    Read the rest of the thread to learn about how you separate your world into Chunks. The idea is that a Chunk represents some 3D span of voxels, and what you do is actually generate a mesh just for the surface (only faces which touch air are drawn).
     
  23. jordantotty

    jordantotty

    Joined:
    Dec 15, 2011
    Posts:
    77
    Update 2: Added some new biomes today
     
  24. HeadClot88

    HeadClot88

    Joined:
    Jul 3, 2012
    Posts:
    736
    Image is not showing for me.

    Not sure why.
     
  25. Cherno

    Cherno

    Joined:
    Apr 7, 2013
    Posts:
    515
    Hello, I just thought I'd chime in here since I started my own take voxel-based terrain. Specifically, I am creating a remake of the 1993 Amiga classic Hired Guns, and procedural terrain generation is currently pssible in my generator, but I just use it for testing purposes. A game level is only 23x20x23 (xyz) blocks big, so it can be easily done in a few chunks. I have written a bsic save/load chunk function that allows me to edit every position in the chunk and change the type of block (null, wall or water) and each of a block's six faces' materials. The mesh will only have as many submeshes as there are unique materials, so typically very manageable.

    Currently, I am researching two important topics:

    1. Updating the whole chunk takes a second or two if a block is deleted, added or a texture is changed since it is all rebuilt completely, is there a way to only update the "sub-chunk" of the affected cube and it's four neighbours? I have thought about passing an array of the xyz coordinates and let teh mesh genrator only handle these somehow, deleting or adding submeshes as needed. Has anyone done something like this?
    I assume that this kind of "local update" is used by most users here?

    2. What about pathfinding in a 3-dimensional space that gets changed every now and then? So far, I have only used Aaron Granberg's A*star pathfinding with a grid graph, but it won't do any good in this case. Also, how to handle flying enemies?
     
    Last edited: Apr 17, 2014
  26. jordantotty

    jordantotty

    Joined:
    Dec 15, 2011
    Posts:
    77
    Update 3: Weather system, Here's a rainy day
     
  27. Vanamerax

    Vanamerax

    Joined:
    Jan 12, 2012
    Posts:
    938
    looking good jordan! Maybe you can darken the terrain a bit, as it seems too bright for the skybox
     
  28. jordantotty

    jordantotty

    Joined:
    Dec 15, 2011
    Posts:
    77
    Update 4: Day Night Cycle + Finished Threading everything (100FPS no lag spikes *finally*)
     
  29. ZeoWorks

    ZeoWorks

    Joined:
    Dec 13, 2012
    Posts:
    76
    Awesome! Will you be releasing this Jordantotty?
     
  30. jordantotty

    jordantotty

    Joined:
    Dec 15, 2011
    Posts:
    77
    Yep! Hopefully by the end of the month
     
  31. jordantotty

    jordantotty

    Joined:
    Dec 15, 2011
    Posts:
    77
    Update 5: Running smoothly on mobile :)
    (Photo taken from my iPhone 5)
     
  32. Vanamerax

    Vanamerax

    Joined:
    Jan 12, 2012
    Posts:
    938
    Hey guys, just uploaded my 7th video update of my game, showing all the voxel terrain related progress:

     
  33. jordantotty

    jordantotty

    Joined:
    Dec 15, 2011
    Posts:
    77
    Wow that looks great! I feel like building a huge bunker in it haha.
     
  34. justin35f

    justin35f

    Joined:
    Jan 19, 2013
    Posts:
    37
    Hey everyone,

    I'm having a bit of trouble with my biomes right now. When I started, I just used the same simplex noise generators for the terrain height, but then I decided it made sense to have a different set of generators per biome. (So that plains will be generally flat compared to a mountainous area). Unfortunately, this has the side effect of not blending well at biome boundaries.

    $BiomeCutoff_zpsf59ab796.png

    Biomes are generated by having each voxel calculate a temperature and precipitation, then using a modified Whittaker diagram. I thought I would use these values to help weight the height, but unfortunately they are too erratic, and don't blend well at the borders.

    After a lot of Google-fu, it seems the consensus is to lerp between the biome boundaries, but I can't think of how to determine the distance a particular voxel is away from a biome border. (That was actually what I thought using the temp/precip values would get me).
     

    Attached Files:

    Last edited: Apr 22, 2014
  35. jordantotty

    jordantotty

    Joined:
    Dec 15, 2011
    Posts:
    77
    You might be over thinking it a bit, check this out if you haven't already https://forums.bukkit.org/threads/t...e-to-terrain-generation-part-7-biomes.164484/
     
  36. Vanamerax

    Vanamerax

    Joined:
    Jan 12, 2012
    Posts:
    938
    Thanks! haha I occasionally derp around with it as well, making the most rediculous buildings you can imagine. I have to refine the building on a small scale though (probably need dual contouring for that to work well)
     
  37. justin35f

    justin35f

    Joined:
    Jan 19, 2013
    Posts:
    37
    That links great and all, but not really applicable. It literally is for Minecraft, and doesn't get into any of the 'nitty-gritty' details of implementation. It just brushes over a few of the finer details, and keeps most of it's focus on larger, less useful details.

    An example would be this:

    "Bukkit provides every chunk generator with a BiomeGrid object. It allows you to read the suggested biome of a region, and also set it. If you set a biome using this object, future calls to block.getBiome() and world.getBiomeAt() will return your biome, and this is the biome that is sent to the client."

    The issue is that these functions do the magic I am seeking, and they are not documented in there. Either way, I've just moved away from per biome terrain features for the time being, and am just doing it all globally now.

    Here's what it looks like so far. (Ignore the trees, it's just a placeholder while I figure out how I want them to actually look.)

    $BiomeBorder_zpsf10e23e3.png
     
  38. ENNEMMEE

    ENNEMMEE

    Joined:
    Apr 4, 2012
    Posts:
    32
    Hey, guys... love this thread ;)
    I'm currently starting my own voxel approach but I'm not sure on how to do the texturing stuff as I would love to have hi-res textures instead of that pixel-retro-style. How could I accomplish this? A texture atlas is fine, but it's limited to the maximum texture size. Creating a mesh for each and every texture results in lots of draw calls and weak performance in the end. My idea is to take the middle between those two approaches: use a texture atlas that is limited to a certain amount of textures and then create different meshes with different texture atlases...

    Or is there a better way?
     
  39. sandboxgod

    sandboxgod

    Joined:
    Sep 27, 2013
    Posts:
    366
    Oh wow never noticed this thread before. This quite refreshing to see everyone sharing their progress. Now I have to get caught up on this thread (100+ pages!)

    Not working on this sort of thing myself atm but very interested in the topic
     
  40. Cherno

    Cherno

    Joined:
    Apr 7, 2013
    Posts:
    515
    I'll just post some code bits plucked from my mesh generation script, it probably won't make much sense with most of the lines missing but you might get the idea anyway. Below is also a TL;DR of the principle. I could upload my complete script if it helps.

    I have done it as follows:

    Before generating the mesh, I fill a dictionary (string, string) with materials for each cube position (xyz). It looks like this:

    private Dictionary<string, string> matDictionary = new Dictionary<string, string>();
    matDictionary.Clear();
    for(x = 0; x < xSize; x++) {
    for(y = 0; y < ySize; y ++) {
    for(z = 0; z < zSize; z ++) {
    matDictionary.Add(x + "," + y + "," + z + "," + "t", "floor1a");
    matDictionary.Add(x + "," + y + "," + z + "," + "n", "wall1a");
    matDictionary.Add(x + "," + y + "," + z + "," + "e", "wall1a");
    matDictionary.Add(x + "," + y + "," + z + "," + "s", "wall1a");
    matDictionary.Add(x + "," + y + "," + z + "," + "w", "wall1a");
    matDictionary.Add(x + "," + y + "," + z + "," + "b", "floor1a");
    }
    }
    }

    This is only done if a new chunk is created so each face has a material in the dictionary.

    Now, the dictionary contains information about the materials that should be used for each of the six faces of one block, regardless if they are visible or not. Its important that all six are assigned so it works right if the chunk mesh is modified during the game and a face is created.

    We also need a global material list that contains ALL mateirals the chunk could possibly have:

    private Dictionary<string, Material> globalMaterials = new Dictionary<string, Material>();
    globalMaterials.Clear ();

    globalMaterials.Add ("invisible", Resources.Load ("Materials/Misc/invisible") as Material);
    globalMaterials.Add ("floor1a", Resources.Load ("Materials/Terrain/floor1a") as Material);
    globalMaterials.Add ("floor1b", Resources.Load ("Materials/Terrain/floor1b") as Material);
    globalMaterials.Add ("wall1a", Resources.Load ("Materials/Terrain/wall1a") as Material);




    Then, we need two lists for each submesh the chunk will have:

    subMeshList = new List<List<int>>();
    subMeshList.Add (new List<int>());

    subMeshMatList = new List<string>();
    subMeshMatList.Insert (0, "invisible");

    We have to add one list to subMeshList immediately after declaring it, and also add one material name to the subMeshMatList that corresponds to it. This is because in Unity, even if all triangles are members of submeshes, the engine still assigns the first material in the gameObject's material list to each triangles, submesh or not. These materials lie under the actual material that is assigned to the submesh, but will become visible if you use transparent textures. This is why we just add an invisible material (0% transparency in the diffuse slot).

    When creating the face of a cube, we have to do some things for the submeshes. I will only post the additional code that goes into the function that creates one single face. This example is for the top face of a cube.

    List<int> subMeshTriangles = new List<int>();
    subMeshTriangles.Add(vertexIndex);
    subMeshTriangles.Add(vertexIndex + 1);
    subMeshTriangles.Add(vertexIndex + 2);

    subMeshTriangles.Add(vertexIndex + 2);
    subMeshTriangles.Add(vertexIndex + 3);
    subMeshTriangles.Add(vertexIndex);

    if(subMeshMatList.Contains (matDictionary[x + "," + y + "," + z + "," + "t"]) == false) {
    subMeshMatList.Add (matDictionary[x + "," + y + "," + z + "," + "t"]);
    subMeshList.Add (new List<int>());
    }

    for(int i = 0; i < subMeshMatList.Count; i ++) {
    if(subMeshMatList == matDictionary[x + "," + y + "," + z + "," + "t"]) {
    for(int j = 0; j < subMeshTriangles.Count; j ++) {
    subMeshList.Add(subMeshTriangles[j]);
    }
    }
    }

    After creating all the cube faces, and assigning vertices to the mesh etc, we have to work with the submesh triangles of course:

    mesh.subMeshCount = subMeshList.Count;


    for(int subMeshIndex = 1; subMeshIndex < mesh.subMeshCount; subMeshIndex ++) {
    mesh.SetTriangles(subMeshList[subMeshIndex].ToArray(), subMeshIndex);
    }

    Material[] matArray = new Material[subMeshMatList.Count];

    for(int i = 0; i < subMeshMatList.Count; i ++) {
    matArray = globalMaterials[subMeshMatList];
    }

    renderer.materials = matArray;

    TL;DR: What we have done is each time a new face is created, we check if the material that is assigned to that face in the matDictionary is already in the chunk's material list. If not, then we know that we have to create a new submesh, so we add the submesh triangles and the material to the chunk's submesh list and material list. This means that we only have as many submeshes are we have different materials.
     
  41. ENNEMMEE

    ENNEMMEE

    Joined:
    Apr 4, 2012
    Posts:
    32
    Aaah, that's cool... thanks a lot! I didn't expect a code snippet :-D
    Is performance ok with this approach as it will generate a draw call for each and every material that is used?
     
  42. Cherno

    Cherno

    Joined:
    Apr 7, 2013
    Posts:
    515
    So far, I have only used three different materials for the chunk mesh, plus a seperate water mesh and a few models like doors and switches. I haven't noticed any FPS hickups so far. I originally had a submesh for every face in the chunk, and the resulting material list went into the low thousands, and only then did I notice FPS drops. So I'd say you can have a hundred different materials easily.
     
  43. ENNEMMEE

    ENNEMMEE

    Joined:
    Apr 4, 2012
    Posts:
    32
    Sounds great! Thanks a lot :)
     
  44. Deleted User

    Deleted User

    Guest

    Your main problem is that you are treating biomes as an on/off switch. It is still possible to do what you want your way, but it would require doing the generation in multiple passes analysing biomes first. It gets really complex really fast.

    You basically need to wrap your head around two concepts:
    1. Biomes are not completely different from each other. There should still be basic terrain underneath it and you simply add to it or subtract from it as your biome requires.
    2. Biomes are not simple switches. They should show how far you are from the norm.

    For example, if you cross from "base" to "mountain" biome, at the very age biome function tells that you only have deviated a small amount from the base, so mountain modifier would only very slightly affect the terrain features. Once you move towards the centre of the biome, its features become much more clear.

    As far as terrain features goes, you probably should consider applying all biomes all the time (changing the modifiers), rather then checking the thresholds as you would do for textures etc. (even for textures it's sometimes desirable to let some of the textures "bleed" over the edges, to achieve a more "natural" look)
     
    Last edited by a moderator: Apr 24, 2014
  45. Greggy

    Greggy

    Joined:
    Aug 11, 2013
    Posts:
    7
    hey guys im new to using voxels so i decided to start using cubic worlds package problem is, it doesnt have a terrain save function is there a better package that allows that or even a package which creates more of a cube world look that i can learn with?
     
  46. goldbug

    goldbug

    Joined:
    Oct 12, 2011
    Posts:
    766


    Greggy, this is a great resource for you:
    http://unitycoder.com/blog/2012/10/18/voxel-resources-engines-for-unity/

    it lists several packages and tutorials for this kind of stuff, I am sure you can find something there that can help you get started faster.

    You might want to take a look at my tutorial:
    http://www.blockstory.net/node/56
     
  47. goldbug

    goldbug

    Joined:
    Oct 12, 2011
    Posts:
    766
    This is not a very efficient approach. Dictionary will do a lot of allocations, and you will end up testing the limits of the memory manager very quickly with this. You are creating a lot of strings, which are also allocations. Essentially you are creating millions of small allocations, and you will run into a "too many allocations" error very quickly.

    If you wish to store the material for every single face, a better approach would be:


    Code (csharp):
    1. /* you could also use an enum */
    2. private const byte floor1a = 0;
    3. private const byte wall1a = 1;
    4. ...
    5.  
    6. private byte[,,] matt = new byte[xSize, ySize, zSize];
    7. private byte[,,] matn = new byte[xSize, ySize, zSize];
    8. private byte[,,] mate = new byte[xSize, ySize, zSize];
    9. private byte[,,] mats = new byte[xSize, ySize, zSize];
    10. private byte[,,] matw = new byte[xSize, ySize, zSize];
    11. private byte[,,] matb = new byte[xSize, ySize, zSize];
    12.  
    13. for(x = 0; x < xSize; x++) {
    14.     for(y = 0; y < ySize; y ++) {
    15.         for(z = 0; z < zSize; z ++) {
    16.  
    17.             /* I assume you ahve some conditional based on the block to determine the material
    18.               and not just assigning the same materials for every block */
    19.             matt[x,y,z] = floor1a;  
    20.             matn[x,y,z] = wall1a;
    21.             mate[x,y,z] = wall1a;
    22.             mats[x,y,z] = wall1a;
    23.             matw[x,y,z] = wall1a;
    24.             matb[x,y,z] = floor1a;
    25.         }
    26.     }
    27. }
    28.  
    you only do 6 allocations that are highly compacted, comparisons are much faster, indexing is much faster, and you have great cache locality.

    _but_, I would question why you need this structure in the first place, when you are rendering, just check what block you are looking at, and decide based on it what material to use for each face.
     
  48. Cherno

    Cherno

    Joined:
    Apr 7, 2013
    Posts:
    515
    Yes, it's probably very unoptimized. I haven't worked with bytes before. The reason why I have these string dictionaries is because I want to use the string to Resources.Load the materials, and also to load and save the map file. Thanks for the suggestion. I'm not sure it's applicable in my case, but I might look into optimizing it. My chunk is only 23x20x23 (xyz), no endless terrain etc. the only thing that's caugins slight lag is the mesh collider, if I disable it's assignment then all changed are "instant".

    How would I let the renderer know which actual material corresponds to each byte? Do I need another dictionary <int, Material> that takes the byte number and returns the corresponding material?

    Am I limited to 255 different materials? (Should be more than enough though ;) )
     
    Last edited: Apr 25, 2014
  49. ENNEMMEE

    ENNEMMEE

    Joined:
    Apr 4, 2012
    Posts:
    32
    If you're using byte variables/arrays then you're limited to 256 materials, yes - using int variables/arrays extends this but also raises memory usage. But as you said, 256 should be more than enough.
    If you like to have strings you could just simply use a global lookup array:

    string[] materialnames = new string[materialcount];
    materialnames[0] = "floor1a";
    materialnames[1] = "wall1a";
    ...


    OR: why not populate an array with the materials?
    Material[] myMaterials = new Material[materialcount];
    myMaterials[0] = ...
     
    Last edited: Apr 25, 2014
  50. jordantotty

    jordantotty

    Joined:
    Dec 15, 2011
    Posts:
    77
    View from inside a cave :)
     
Thread Status:
Not open for further replies.