Big announcement. I’ll be temporarily stopping development of this project and blog to pursue a career as a city councilman in local politics. The election is roughly six months away and I’ll need to commit the entirety of my free time to raising money and campaigning. While working with particles in Unity brings me passion, I know my true purpose lies in bettering my community through public service. I know that the city of Miami will truly benefit from a young, educated, disciplined, self-motivated, moral, humble person like myself joining the throng. My purpose drives me.
Anyways, I realized that intercepting the correct SDF output really means intercepting the correct mesh. The mesh that gets sent to the Bake Tool doesn’t output correctly if I call it from my script, but it will output correctly if I save the mesh using that handy MeshSaver tool and then send it over. Therefore, I need to look at how MeshSaver accesses the mesh and figure out why it works. That logic sounded all good and well, until I looked at MeshSaver and saw how simple it was:
public static void SaveMeshInPlace (MenuCommand menuCommand) {
MeshFilter mf = menuCommand.context as MeshFilter;
Mesh m = mf.sharedMesh;
SaveMesh(m, m.name, false, true);
}
public static void SaveMesh (Mesh mesh, string name, bool makeNewInstance, bool optimizeMesh) {
string path = EditorUtility.SaveFilePanel("Save Separate Mesh Asset", "Assets/", name, "asset");
if (string.IsNullOrEmpty(path)) return;
path = FileUtil.GetProjectRelativePath(path);
Mesh meshToSave = (makeNewInstance) ? Object.Instantiate(mesh) as Mesh : mesh;
if (optimizeMesh)
MeshUtility.Optimize(meshToSave);
AssetDatabase.CreateAsset(meshToSave, path);
AssetDatabase.SaveAssets();
}
The only thing I could think to try was using Instantiate(mesh) in my Bake Tool call. That didn’t work. I ended up staring at MeshToSDFBaker’s Init() function which creates the Bake Tool’s compute shader, feeling like I may as well have been looking at Chinese.
But guess what?! Today, is April Fools, and I’m one damn lucky fool.
Yup, that’s right. Metaballs are working in my VFX graph(!!!), and once again, I got things working by going over to my demo project that I planned to use to submit a bug report to Unity (see post on 3/28/24) and attempting to recreate the bug. Just like last time I tried recreating a bug, I found out I no longer had one. April Fools, right? I’m not sure what exactly fixed this, and it’s late, so I’ll just leave work happy and go home.
One thing I did realize, though, is that I don’t need to be modifying the VFX graph package, since I can access the properties of the mesh (center and size) before I pass it over to the SDF Bake Tool. That’ll help me clean my project a bit and not have to worry about missing updates to the VFX Graph package.