blurstudio / TwistSpline

A smoothly reparameterizing Bezier spline that also interpolates orientations
MIT License
96 stars 43 forks source link

Implemented a new NURBS output plug, added icons, AETemplates and a 2025 variant to github actions #27

Closed mdilena closed 3 months ago

mdilena commented 3 months ago

Checklist

Types of Changes

Proposed Changes

This is another update I've been sitting on for a while, as the first time I used this plug-in on a project I ended up needing nurbs representation of the spline too, so I figured I could give it a try. I also took the chance to clean up some code that I found out was unnecessary for what regards the new viewport 2.0 implementation, adding icons, attribute editor templates and making sure github actions are all up to date with latest stuff. I also fixed the plug-in version and bumped it to 1.1.0, as I think we're past beta by this point, guess I considered 1.0.0 the previous merge request I made :grin:

I also moved the gifs to a local images folder, as it's nice to have them when the repo is cloned offline and the website is not reachable!

Don't mind twistSpline.h and twistTangentNode.cpp changes, they're only whitespaces and it's because I accidentally included some experiments I was doing and rolled them back, they got trimmed when I re-saved the file :sweat_smile:

tbttfox commented 3 months ago

Icons? Nice! And you're right, it's definitely out of beta by this point. I really appreciate this. And fair enough with the images, but I'm curious why the xpm's as well as the png's? I'll run these changes through our code to make sure it doesn't break anything, but everything looks good at first glance.

The only issue I have is how you built the knots array. Because the knot values are the parameterization of the spline, I think you should build the knot array by doing spline->getRemap(), and repeat each value from that vector 3 times. That way you get the auto-reparameterization that comes from the locks and pins of the twist spline (at least for translation)

mdilena commented 3 months ago

The .xpm is for the Node Editor and it's picked up automatically if it shares the same name as the node, while the png is scaled down to look nice in the outliner - I just realized I may have to provide _150 and _200 dpi resolution for that too - and is assigned through the code. Before I did that, the outliner one looked really bad and pixelated! Also, I forgot to include the twistTangent node one, so I will push it soon.

Regarding the knots, I really wanted to hear your opinion on that, as I'm really no expert on NURBS and I remember it took me a while to get it right. What you mentioned makes total sense! I took a quick look at the spline->getRemap() array and tried to print its values to get an idea of the data in there, but I can't fully understand how I could use it to build the knots array. Would you mind explain what you had in mind? Is it related to the first values in that array? If I build the spline with your python script (so with 4 controls), the first 4 values in that array are [0.0, 3.0, 6.0, 9.0], they seem to be the only one who recall some parametrization to me.

Thank you!

tbttfox commented 3 months ago

Ah, cool. I didn't know that about the xpm's.

And the knot vector should be really easy. Because the twist spline will never be anything but a cubic bezier curve, you can get rid of all that extra logic and just repeat each value from remap 3 times in a row.

std::vector<double> remaps = spline->getRemap();
MDoubleArray knots(remaps.size() * 3, 0);  # we know the length of the array, so we only need to allocate once.
unsigned int c = 0;
for (double p: remaps){
    // set the value 3 times
    knots[c++] = p;
    knots[c++] = p;
    knots[c++] = p;
}
mdilena commented 3 months ago

That worked great, tested it and generated correctly both a NURBS and a Bezier curve! I also added all the missing icons :slightly_smiling_face:

tbttfox commented 3 months ago

I tested and it works great! Thanks a bunch for your PR