This is over 4 times faster than my last implementation. The difference? I threw out all of the Vector3 and CFrame references I possibly could and did all the math by hand. I removed as many tables as I could, and stuck with only one table for all the coordinates of the points of the cloth. I also made as many shortcuts as I could to make sure I made as few table references as possible and simplified all the math down to as simple and as quick as it could possibly be.
I’ll release this sometime when I make functions to easily set the positions of the points of the cloth. I’ll also speed it up a bit more, too.
Okay, so I’m doing object oriented stuff for the first time. Hate it and I feel like a sellout because object oriented stuff requires table searches which requires time which is time that should be spent doing something else, even if it is just a few nanoseconds. Whatever.
I worked on the math, and for an increase in 3.125% (0.5^5) in jitteryness, I sped it up by more than double. Yes. It’s now twice as efficient! AND IT’S STIFFER! I could do more, but the increase in jitteryness might bug people. So I’ll come up with an equation or something so that way people can define max jitter… Which is exceedingly easy now that I think of it. OverConstrain=(MaxJitter)^(1/ConstrainIterations)+1
Also, I added the ability to set position of points. And the ability to color squares of the cloth. And Set the gravity, and set whether points on the cloth are anchored. Also I added shear forces.
Well, this has more to do with performance tuning than math. Really having a deep intuitive understanding of how much each operation you’re doing costs, so that you can find the most efficient way to do the stuff. AxisAngle probably knows that the best of anyone on this forum by now after doing his few months worth of performance experiments.
Did you include any loop unrolling? If you really want to speed it up, you could probably squeeze out another chunk of performance increases by doing some loop unrolling… at the cost of every last drop of readability remaining in the code of course.
I’m currently in the process of removing unnecessary loops, which I have many of. I can make a lot of performance improvements to the code, but I’m going to have to rewrite a lot of my logic. …Shouldn’t be too hard.
Also, I’m going to combine several loops and cache a lot of table references in locals, cutting the number of table references in half. That should be another big one.
I would just make the place open-source but it uses trey’s code to fit the triangles to the three points I define and he hasn’t released that code yet so I don’t want to go behind his back or anything.
The coil is really simple. You’ll notice rings that form where a bunch of triangles meet. Those rings, the segments, are what’s actually moving and all the triangles are doing is fitting onto them. The segments are generated on a coil and they have a position offset and a radius offset, which are both functions of time offsetted by the index of the segment, so the segments aren’t really moving as much as they’re reflecting a change in time.
After you understand how the coil works, the squirt gun is extremely easy. I think I made it in about thirty minutes. Really all it is is a coil where, instead of dynamically calculating the positions of the segments, the segments are all at fixed points that are defined before the triangles are even generated. Once again they have position and radius offsets based on time. I can modify the radius offset to make the segments paper-thin when they aren’t active, which gives the impression of motion even though the segments are once again not really moving from where they started. The splash at the end is another example of modifying the radius, this time based on how close the segment in question is to the final segment.
Hoping I didn’t accidentally hijack the discussion here. As much as I love cloth I think this super fast triangle math could also be used for a lot of other awesome stuff too.
In case you can’t see what’s going on from the gif you can see the coil and the squirt guns at a smooth 60 FPS here. (okay maybe not the squirt gun, I haven’t optimized that yet).