Code Monkey home page Code Monkey logo

marching-cubes's Introduction

Marching-Cubes

Using objects represented by a 3d array of data has become quite popular in games in the last few years. Voxel terrain is probable the most common application. Of course GPUs only understand triangles so the voxels have to be converted to a mesh some how.

The most common algorithm for doing this is called the marching cubes algorithm. Examples of code are very common on the internet. One of the best ones around in my opinion is this one here and it is what I have based my code on. The thing I like about this code is that it also implements the marching tetrahedron algorithm that is a little more difficult to find good examples of. The marching tetrahedron algorithm produces a mesh that matches the voxel data much better than the cubes algorithm but produces far more vertices.

Marching Cubes

Update - Added the option to create smooth normals.

Marching Cubes

marching-cubes's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

marching-cubes's Issues

OpenVDB support for Unity

I know it is not exactly related to this project, but it would be great to provide support for OpenVDB on CPU/GPU. There are many great functionalities related to voxels, and I think marching-cubes is also available.

Attaching a texture to a mesh

Hi, for the my project, you need to attach the texture catra to the mesh.
Can you help with this?
Or I can complement your project.

Point Cloud input data

I would like to add an option for allowing the user to use an array of Vector3's as the input, instead of the fractal noise. How would you recommend going about this?

List of indices is never used?

Hello, i've been messing around with your project for a while, and i've noticed that the IList passed as parameter to the March() method is populated but never used in your code example. Is this intended?

Here you rebuild all the indexes manually.

`for (int i = 0; i < numMeshes; i++)
{

            List<Vector3> splitVerts = new List<Vector3>();
            List<int> splitIndices = new List<int>();

            for (int j = 0; j < maxVertsPerMesh; j++)
            {
                int idx = i * maxVertsPerMesh + j;

                if (idx < verts.Count)
                {
                    splitVerts.Add(verts[idx]);
                    splitIndices.Add(j);
                }
            }`

Added Color.

Hi there,
thanks for the great work, it was very useful.

Please find enclosed an enhanced version working with colour.
Vertex color info is propagated to edges during marching.

MarchingCubes.zip

screenshot 2018-01-23 16 19 24

Many thanks,
Xavier.

Mesh generates above surface for one block thick!!

Hi,

Sorry for asking for help again. Well this is more about bringing up an issue with the code. Basically I have found that in the positive x, y and z directions, a layer of "empty" will build as though its actually the ground.

Here is an image showing the problem areas:

Good side:
image_2022-06-20_153208885

Bad Side:
image

Everywhere you see BLACK or NOTHING is where there are air blocks in my game. Air blocks should be "above" the surface of the mesh since the mesh should be all the land in the world and not the air.

At first I thought this was a uv mapping issue since I build that part myself and assumed I must have poorly integrated something. However, I debugged block types for a 5 by 5 region of land and air and from that I can tell that the block is air blocks and not wrongly mapped land blocks like grass and dirt.

I believe this comes from the fact that a blocks generated section of the final mesh is not centered on the block position but rather the blocks position is the bottom-left-back corner of the block.

Would you happen to know how to fix this? I understand that when using the marching cubes code at large scale without textures, it seems fine. But for my game this is completely unusable if this stays in. Any fix is fine, even patchy/hacky fixes for the time being.

Please let me know if you need any clarification on the issue. I am more than happy to create some way to visualize the issue further!

Thank you!

UV Mapping?

Hi,

I found this project recently and find it really cool. I was looking to make something like this but your design is way better than what I was gonna do. However, I noticed that there is no UV mapping it seems.

I am making a game "like minecraft" but I need each block to have its own texture. To do this I just need to generate the uv coords for each triangle. I actually managed to integrate this code well with mine and I have it generating a assumptive set of uv coords but they are not aligned correctly to the "quads" of each block since I am just aligning them the the triangles. So some textures are flipping around and not showing completely.

Is there any way you can implement correctly aligned quad uvs along with the verts and triangles. Or direct me on how I might go about it

I have this texture as a debug texture that I am trying to put on the blocks:

Screenshot 2022-06-17 213026

However this is the result with my method:
Screenshot 2022-06-17 212732

Here is the underlying geometry at that location (zoomed out but smaller image cause I suck at getting screen shots):
Screenshot 2022-06-17 212912

Ass you can see, the bottom right half of the texture is not being mapped because all the uvs are pulling from these coords: {x:0, y:0}, {x:1, y:0}, {x:1, y:1}.

It seems there is nothing I can pull from to check if the current triangle is the top left triangle in the quad or the bottom right.

This whole question might not be possible to solve, however, since many of the "quads" are skewed which means that the textures will be skewed. And if we were to attempt to place uvs in a way that made them not skewed, it would not tile along each "block"

Anyways thanks for the code!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.