friggog / tree-gen

Procedural generation of tree models in blender
GNU General Public License v3.0
827 stars 74 forks source link

Add option to automatically simplify branch geometry #5

Closed samipfjo closed 6 years ago

samipfjo commented 6 years ago

When exported to an FBX or OBJ, curves are automatically converted to meshes. The way that Blender does this, however, results in tons of unnecessary geometries. This PR provides an option to do this process in a more optimized manner automatically.

First, the branches curve is converted to a mesh. Second, a limited dissolve is run on the mesh to remove unneeded faces / verts / etc. These two steps are not terribly difficult to do on one's own, but including this option is a great QOL improvement in my opinion.


Here is a comparison of a FBX exports of a Quaking Aspen model:

Filesize using curves: 38.1 MB

Curves converted to mesh 867,624 verts | 839,760 faces | 1,679,520 tris Filesize: 38.1 MB

Simplified branch geometry -- mesh view 546,102 verts | 254,653 faces | 724,716 tris Filesize: 18.8 MB

Savings: 321,522 verts | 585,107 faces | 954,804 tris

samipfjo commented 6 years ago

As a side note, doing a limited dissolve through Blender's UI will produce a few strange unwanted faces between branches. This can be fixed by tweaking the angle limit, which is already accounted for in this implementation. Around 1.5 radians appears to work fine. We could add an input box for users to customize the limit if need be, but I don't think there be a need :)

friggog commented 6 years ago

The bezel parameters (resolution) can be controlled directly, though are currently hard coded here and here.

I definitely think a convert to mesh option is valuable - it may also be useful to include the bezel options above somehow, though I guess these can also be controlled directly using the default blender UI. I agree that an input box for that option isn't necessary.

samipfjo commented 6 years ago

Just a heads-up, I've added a couple of unrelated commits, one of which is fairly significant.

I would have made a separate PR but I honestly don't know how to do that via the Windows GitHub application.

Edit: I've now read the GitHub documentation on pull requests and will avoid doing this in the future.

friggog commented 6 years ago

I made a lot of formatting fixes so you'll need to pull the latest master before making any more changes. In terms of style I tend to try and stick with Pep8 and no trailing whitespace, there are lots of plugins to auto format python according to this.

As for Git usage, it would be best to create a new branch feature/[whatever_name] for each significant feature and work on that, then do a PR from that into master. It's then a lot easier for me to pull, review and modify any changes without screwing stuff up.

One other option I just thought would be to have a toggle for leaf generation as it can take a long time and in some cases people may not want the leaf mesh. Otherwise it's really taking shape, great work!

samipfjo commented 6 years ago

I always do my best to stick with PEP8, but there was an extent to which I was trying to not deviate from the original codebase too much. I've never used a PEP8 checker before, but I'll be sure to run the code through before future submissions. The whitespace issue was really sloppy on my part, sorry about that.

I don't have much experience contributing to OSS, so my previous Git usage has mostly been private projects (and subsequently a bit of a bodge). Sorry for putting you through the brunt of my learning; I really appreciate your patience and willingness to help me navigate the waters.

Adding a checkbox to disable leaf generation should be quick and straightforward -- I'll get a PR sent in soon.

Thanks! It's been a ton of fun contributing to the project; I've learned a lot about Blender, and I'm getting addicted to the "greater good" feeling of OSS contribution. Looking forward to the future of the project!

friggog commented 6 years ago

Ahah no worries, on personal projects I tend to just work on master and it's ok, but as soon as you are collaborating branches become pretty essential. Let me know if you have any questions about the existing code. Hopefully it's reasonably well commented, but it evolved quite a lot throughout the project so may be a bit messy in retrospect!