This log also includes the work I did on 11/29/23

I implemented the SDF Bake Tool into my mesh combiner script using code I adapted from this guide, and voila, a multi-mesh, dynamic SDF! I found that I actually didn’t even need to do any of the mesh combining myself, as the Bake Tool’s MeshToSDFBaker class has the ability to combine several meshes together via its internal InitMeshFromList() method, which takes a list of meshes and transform matrices and combines them. Perusing that method’s code showed me how the pros over at Unity combine meshes (my code seems good enough though).

Feeding multiple meshes to the SDF Bake Tool was trickier than it needed to be. My objective was to scrape mesh data from all child game objects in order to populate InitMeshFromList() mesh and matrix lists. Invoking Unity’s GetComponentsInChildren() method, however, resulted in me getting an undefined object error. I initially worked around the error by predefining a list of game objects to use via the inspector and then sending mesh and transform data from those game objects into the method. But, since I preferred to be able to grab the meshes automatically via script, I was not satisfied. After spending an unnecessarily long amount of time trying to figure out how to do so, I noticed the solution in plain site. The example in the guide by Qriva automatically populated the mesh and transform lists by creating an array of MeshRenderers using the FindObjectsOfType() method. I’m not sure why GetComponentsInChildren() didn’t work but that method does; I’m chalking it up to a unitybug. Instead of using a layer mask to isolate the desired mesh renderers like the guide did, I checked whether each mesh renderer was a child of my script’s game object.

While on this OCD binge (I say that because truthfully I already had working code for my intents), I stumbled upon a very handy asset called Naughty Attributes. For my code, I used it to conditionally show/hide and enable/disable specific properties in the inspector.

I’m able to dynamically update the SDF bounds using the mesh data. To get the mesh from the InitMeshFromList() method, I had to modify the protected MeshToSDFBaker class. I did this by copying the VFX Graph package back into my project’s packages folder with write permission, courtesy of this tip. Little tricks I pick up here and there, ya know?

I still haven’t explored the mesh-to-sdf package, but since my scene’s FPS hasn’t dropped much at all (still around 300), I may not even need to. Worth noting, SDF Bake Tool’s mesh combiner works slightly more efficiently than my own.


Tags: unity gamedev vfx sdf mesh scripting