Hi all, here is some new functionality for Path3D I’ve been working on, please tell what you think about it or what else could be added, I will then make a PR.
- New constructor/update parameter: alignTangentsWithPath (false would make it look like it does now by default):
-
New function: getPointAt (also for Curve3) this will get an interpolated point somewhere along the curve, from 0.0 to 1.0 (note: in Path2 it’s called getPointAtLengthPosition).
-
New functions: getTangentAt, getNormalAt, getBinormalAt, getDistanceAt. They take two parameters: a position from 0.0 to 1.0 like getPointAt, and an optional boolean (not for getDistanceAt) of wether to interpolate them as well. If chosen not to interpolate, the actual tangent/normal/binormal from the precomputed array is returned, not a clone of it.
-
New function: getPreviousPointIndexAt. This returns the array index of the previous point of an interpolated point along the curve.
-
New function: getSubPositionAt. This returns the position of an interpolated point relative to the two points it lies between, from 0.0 (point A) to 1.0 (point B).
-
New function: getPoints. This is the same as getCurve. Added to allow for more compatibility between Curve3 and Path3D (e.g. a function not having to check which one is provided).
-
New function: length. This just returns the last value of the distances array. This will also allow for more compatibility between Curve3 and Path3D.
Edit #1:
- New function: slice. (also for Curve3) This returns new sub path/curve from a starting point to an end point (0.0 to 1.0). Just like slicing an array, both the start/end points are optional, and negative values wrap around from the end of the curve. If the starting position is greater than the end position, they get swapped instead of returning an inverted slice. (with arrays, an empty array would be returned)
Edit #2:
- New function: getClosestPositionTo. This returns the position of the closest virtual point on the path to an arbitrary Vector3, from 0.0 to 1.0.
Demos:
alignTangentsWithPath: true
interpolate: false
https://croncle.blob.core.windows.net/babylonjs/playground/index.html#JFY9IM#5
alignTangentsWithPath: true
interpolate: true
https://croncle.blob.core.windows.net/babylonjs/playground/index.html#JFY9IM#6
getClosestPositionTo
https://croncle.blob.core.windows.net/babylonjs/playground/index.html#ILWJ9M#2