April 01, 2018 - Optimized Mesh Cutting

Faster, faster, faster!

In my previous blog post I had focused on aesthetics but for the past month I dove head-first into the code and found a ton of opportunities to squeeze more performance out of it. I think part of my change of pace had something to do with the fact that GDC 2018 was going on and I was not attending, but I used that as a way to motivate myself to do some hardcore programming. And then I took to twitter and decided to post as many videos as I could while GDC was going on.  And I probably burnt myself out in the process, but it was pretty fun.

Here's a list of some of the improvements I've made:

1) Async cutting - The first major update is what I think can be called "asynchronous" mesh cutting which basically means that it no longer interferes with rendering thereby reducing judder which is fantastic for the VR experience.

2) Cached Edge Cuts - I thought it might be useful to cache each cut edge when cutting a mesh because chances are that edge would need to be cut again for an adjacent triangle.

3) Storing cuts in local space - By "storing" what I mean is that when the start of a cut is detected I add it to a dictionary until the blade exits the object at which time it goes into a queue. Since time is passing between each event I was getting wonky cuts in the past because they were being stored in worldspace. I've finally corrected that!

4) Performance updates:
  - Re-ordering vertices for new tris so the normals don't need to be double-checked and flipped
  - When capping cut sides, skip over colinear edges to reduce complexity for subsequence cuts
  - "Playdead Optimizations" - some refactoring based on advice given in this video from UniteLA 2016
Unite 2016 - Tools, Tricks and Technologies for Reaching Stutter Free 60 FPS in INSIDE

5) Garbage Collection - I'm manually triggering garbage collection to make sure that it doesn't accumulate a massive GC operation. This might be cheating, I can probably rethink this and use only pre-allocated space instead. I'm thinking about it...

This was a pretty intense month considering how difficult it was to update the meshcut algorithm which wasn't my own to start with. I like to think of my process as reading code and internalizing it before I can start improving upon it. I have a lot of respect for the original author of this code and I learned a lot from it. The original code can be found here: https://github.com/BLINDED-AM-ME/UnityAssets


Outstanding issues:

1) the cutting action script it attached to the blade object, and that script contains the queueing mechanism which performs cuts one-at-a-time. This is a problem when there are a bunch of cuts in the queue and you switch off the blade which puts the cutting on pause until the blade turns back on.

2) the first time you switch on the blade it plays the "switch off" animation. You can kind of see it at the beginning of this video. Super annoying. I need to fix that soon.

Wish list:
1) haptics!
2) lefthand/righthand switching
3) start introducing enemies, maybe a simple robot to start with
4) skinned mesh cutting


What I'm watching


I want to recommend this youtube channel:
https://www.youtube.com/user/ThinMatrix

This developer makes the best dev log videos I've ever seen. I really want to start making similar videos but I never feel like I have time. In fact, one of the reasons my current post took so long was because I was trying to edit together some clips but it didn't come out to my liking.

Here's his latest video:



Comments

Popular Posts