Jump to content

Hermite Spline added in Curve3


Recommended Posts

Added methog length() to curve3 : returns the total length of the curve
Added the Hermite Spline curve to the curve3 collection.

var hermite = BABYLON.Curve3.CreateHermiteSpline(p1, t1, p2, t2, nbPoints);
  • p1 : initial point
  • t1 : initial tangent vector
  • p2 : final point
  • t2 : final tangent vector


This curve is based on the internal BJS Vector3.Hermite.
It is very useful to smoothly continue or close other curves by using their first and last segments as Hermite tangents.

example : smoothly closing two concatened cubic bezier curves

// two concatened cubic Beziervar cubicA = BABYLON.Curve3.CreateCubicBezier(vA0, vA1, vA2, vA3, 50);var cubicB = BABYLON.Curve3.CreateCubicBezier(vB0, vB1, vB2, vB3, 50);var continued = cubicA.continue(cubicB);// initial Hermite values from continued first and last segmentsvar t = continued.length() / 2;                             // tangent scale factorvar points = continued.getPoints();var p1 = points[points.length - 1];                         // last continued point = first hermite pointvar t1 = (p1.subtract(points[points.length - 2])).scale(t); // last segment scaled = hermite tangent t1var p2 = points[0];                                         // first continued point = last hermite pointvar t2 = (points[1].subtract(p2)).scale(t);                 // first segment scaled = hermite tangent t2var hermite = BABYLON.Curve3.CreateHermiteSpline(p1, t1, p2, t2, 50);continued = continued.continue(hermite);// finally drawing a smooth closed curvevar closedCurve = BABYLON.Mesh.CreateLines("closed", continued.getPoints(), scene);
PR pending


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.

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.


  • Recently Browsing   0 members

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