Car Commercial – 10 – Stick To Surface
November 4, 2017
So with the most recent updates on the lightning sim, we have an awesome comp thanks to our compositors Abby Riegel and Rachel Clarke!
This is obviously really cool looking, but I wanted to change a few things about the simulation, one of which being the static points. At the moment the points are just completely static on the car and the ground. If they move around a bit it will add some more believably to the random nature of the lightning as it streaks across the car and ground. So how to go about this. I have always been pretty interested with having points glide on the surface of a mesh, so I have a little back thought to this. Sadly I don’t have any notes written on this in my notebook, I drew my ideas out on a white board so they are all lost now π
Inside of a Solver Sop we use basically the same system as created hereΒ for Wandering Points on a 2D surface. We initially update the position based on the velocity, then we snap each point to its relative surface, then we generate and update the velocity for the next frame. This all works with the same code from the Wandering Points with just the snap to surface node shoved in there. This is pretty interesting to me because it proves this system is pretty much modular and I could swap out other snippets of code or what not to create a whole new particle system. Pretty freaking cool if you ask me.
This is the main code for the snap to surface wrangle. The idea here is we search around the point for nearby points, total those positions up, and average them out. We do the same for the normal so we can get a relative normal as well. This method works fine for what we are doing here, it doesn’t return a point directly on the surface of the mesh, but pretty close to it depending on the surrounding points and mainly the curvature of the mesh. If its very curved like the torus used to test, you will get points below the surface, and if its concave you will get points above the surface. This changes of course with the search radius and how dense the mesh is.
Realistically we could subdivide our mesh and get a large amount of sample points and use a small search radius with a bunch of substeps and probably stick really close to the mesh. But that would take a lot of computing power. We could also just choose the first grouping of near points, rather than points in a certain radius. This way, regardless to how far away from the surface the point is, it will still find a place to stick to. This could also work, but could stick to other pieces of the mesh or start to incorporate points that we may not necessarily want. Again, more substeps are needed. What we have here works perfectly for the simulation.
The points stay near to the surface, keep a correct normal, and stay within their respected boundaries. With this now working, we can use this system on our start points to have them drift and sway around the car itself!