Open taori opened 3 years ago
Hello Andreas,
You are right about the part that the density values represent cells and it gives us information if the cell is solid (has something in it) or empty. Now the caseCode is calculated using a binary operation and it is only responsible for the mesh itself, but not the texturing. The algorithm decides based on the caseCode, where to create triangles.
For texturing I used a UV map, which unfortunately is not the most beautiful solution, but it works, I'm planning to implement triplanar shading however.
To add multiple textures in my code you will need to create a texture atlas. And map the UVs to the vertices.
uvs.Add(uvOffset[vcase]);// uvBase + uvOffset[vcase]);
vcase = (byte)(vcase == 3 ? 0 : vcase + 1);
Currently this is in the Polygonization.cs, this is the code responsible for UV mapping. Now you will have to modify it a little bit.
uvs.Add(uvBase + uvOffset[vcase]);
vcase = (byte)(vcase == 3 ? 0 : vcase + 1);
The uvBase is the normalized coordinate of the bottom left corner of the texture of your choice inside the atlas. The way you store uvBases is actually up to you. I used to store them inside every cell as two bytes (x and y) for performance reasons. And on initialization I just assigned the texture coordinates to the cells.
I hope this solves your problem, but if not feel free to ask, I'm more than happy to help. Also I'm planning to push a little update with some performance changes and multi texture support in the near future.
Thanks for your explanation. It really did help me yes! Now it is time to try implement it after some further changes. This transvoxel stuff sure is a difficult read. haha.
Thanks again!
So i think i have figured out why it isn't working properly for my algorithm. i was looking at this project and another project for guidance. but while yours also has the transvoxel tables too, it does not actually use them but instead uses the ordinary marching cube algorithm
Hello there. Thanks for making this project.
I was wondering if you could help enlighten me on some part of the code: I am trying to make some alteration on the ground so i can have different patches of elements instead of just a grass one but it seems that my whole concept of the casecode logic is flawed.
I have read the original pdf document and concluded from that, that a chunk is divided into cells and each of those cells has edges. which enclose the voxel atoms depending on whether there is an element at this position (any value but zero) or not (value zero)
I was thinking that the sample values currently provided are just randomly generated values to mimic different voxel atom elements instead of having an underlying meaning but that appears to be wrong?
The code in question is this:
My own code is this:
(if i replace the != 0 part with a filter i could then generate meshes for individual elements, iron, copper etc)
My thought was that the density array is nothing but an array of positional information about whether the edge of a cell voxel contains something or not.
I know this isn't your problem but i was wondering if you could perhaps share some of your knowledge on this with me.
Best regards Andreas