Jump to content

A closed polygon of cutmull-splines


TimT77
 Share

Recommended Posts

Hi @TimT77 and welcome to the forum. Sorry for the slow reply but it took some thinking about. Strictly speaking given a set of points p0, p1, p2, ......., pn catmullrom uses 4 points p(i), p(i+1), p(i+2), p(i+3) to draw the spline through points p(i+1), p(i+2), with p(i) and p(i+3) as only control points, and so since p0 and pn have no points in front of and after them respectively  they are not usually drawn. However the `CreateCatmullRomSpline` method of Curve3 compensates for this and draws through all the given points.

A slightly different method is needed if you want the given points to be in a loop. In the following playground I produce a function 'CreateCatmullRomSplineLoop'  (returns a Curve3 object) which will draw a loop through the given points. Note usage as it is not a BABYLON method.

https://www.babylonjs-playground.com/#K49ARR

Link to comment
Share on other sites

Hi guys, sorry for butting-in.  I dunno much about mulling cats, but I think you guys should see this...

https://www.babylonjs-playground.com/#14VFYX

Whenever I hear Catmull-Rom... I think of rounding the edges of mesh.  I know that's not its only purpose, but what the heck... you guys need to see some mesh rounding.

I don't know who did this PG, but I love it.  I think these shapes are quite high-vert-count mesh, but they look SO COOL, huh?  Ok, Wingnut over and out.  :)

Link to comment
Share on other sites

One small change in addition to JohnKs solution:
i've added:

catmullRom.push(catmullRom[0]);

to "CreateCatmullRomSplineLoop":

CreateCatmullRomSplineLoop = function (points, nbPoints) {
    var catmullRom = new Array();
    var step = 1.0 / nbPoints;
    var amount = 0.0;
    var pointsCount = points.length;
    for (var i = 0; i < pointsCount; i++) {
        amount = 0;
        for (var c = 0; c < nbPoints; c++) {
            catmullRom.push(BABYLON.Vector3.CatmullRom(points[i % pointsCount], points[(i + 1) % pointsCount], points[(i + 2) % pointsCount], points[(i + 3) % pointsCount], amount));
            amount += step;
        }
    }
    catmullRom.push(catmullRom[0]);
    return new BABYLON.Curve3(catmullRom);
};

and now i have a closed polygon! ??

 

https://www.babylonjs-playground.com/#K49ARR#1

Link to comment
Share on other sites

@TimT77 thank you for spotting that, my old eyes had not noticed the gap. From V3.3  you can add a true parameter at the end of `BABYLON.Curve3.CreateCatmullRomSpline` to close the curve. However I had made the same mistake when doing the PR so the gap will still appear until the next time V3.3 is updated https://www.babylonjs-playground.com/#1AU0M4#19

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...