4 ms·
I've written my fair share of this sort of code, but it's a very painful way to create geometry. I don't mean to be discouraging. I just did way too much of thi
by slavik81 5y ago
I've written my fair share of this sort of code, but it's a very painful way to create geometry. I don't mean to be discouraging. I just did way too much of this myself, and I regret how much time I spent on custom primatives.
A 3D artist would probably create something like this by cutting the mesh and applying Catmull-Clark subdivision (assuming they didn't have a proper bevel tool). If you have a library of generic mesh manipulation functions lying around, the programmatic way and the artists' way would likely be the same. Creating those generic functions is a lot of work but it pays off fairly quickly. You need generic functions eventually anyway, to create more complex shapes.
It's also worth noting that the optimized mesh has some unfortunate drawbacks. Mesh properties are generally only stored on the vertex, and are interpolated across the attached faces. Having long, thin triangles or big differences in triangle area will often create problems when vertex properties are interpolated across the face. So, you may need to break those big faces into multiple triangles anyway.
- throwaway_2047 5y agoBy generic function, do you mean the catmull clark subdivision?
- slavik81 5y agoThat would be one example of such a function, yes. Libraries like IGL or OpenSubdiv can help you to implement more, too.
- iainmerrick 5y agoHaving long, thin triangles or big differences in triangle area will often create problems when vertex properties are interpolated across the face. That can definitely be a problem in general, but is it likely to crop up in this case? Those long triangles are flat so the normal is constant. Neither 2D nor 3D texture coordinates will have too much distortion. And if it was a problem, you could fix it by scaling back the optimization, no? If you have a library of generic mesh manipulation functions lying around, the programmatic way and the artists' way would likely be the same. Creating those generic functions is a lot of work but it pays off fairly quickly. Yes, you’re right about that. I think this is still interesting and useful from the perspective of understanding how to build a basic mesh programmatically. And sometimes it’s easier to crank something out in a brute-force way like this than to figure out how to combine your general-purpose tools in just the right way.
- NL807 5y ago> That can definitely be a problem in general, but is it likely to crop up in this case? Only issue I can think of is slight loss of precision along big surfaces, as partial derivatives will have bigger deltas. It's only a problem if your fragment shader maths is numerically sensitive to such things.
- slavik81 5y agoIt's fine for use in rendering if this is the final shape and it will never be modified. You're just a bit limited in terms of what you can do with it.
- slavik81 5y agoIt's a beautiful write-up and the technique can be useful sometimes. I just had flashbacks to the literal months I wasted doing this sort of thing for a dozen different shapes and the horror that was stitching them together. I wanted to communicate that the method described is not the way you would go about creating most geometry; you can be much more productive using higher-level geometry operations.