Three.js: getSpacedPoints from CatmullRomCurve3 returns points with the different distance between them

Created on 21 Dec 2016  路  8Comments  路  Source: mrdoob/three.js

I'm trying to get points with the same distance each other like this

var spline = new THREE.CatmullRomCurve3([
    new THREE.Vector3(-5423.1, -109.2, 1765.8), 
    new THREE.Vector3(-4730.6, -258.2, 2154.3),     
    new THREE.Vector3(-4616.0, 364.6, 2018.6),
    ...
]);
var ppiDistance = 15; // breakpoint per distance
var pointsCount = Math.ceil(spline.getLength() / ppiDistance);
var pointsCalculated = spline.getSpacedPoints(pointsCount);

But I'm getting situation like this on different segments:
https://monosnap.com/file/YK23E7VnyxrgX4Esoil2MNo5x3YVns.png

Is it bug?

Three.js version
  • [ ] Dev
  • [x] r82
  • [ ] ...
Browser
  • [x] All of them
  • [ ] Chrome
  • [ ] Firefox
  • [ ] Internet Explorer
OS
  • [x] All of them
  • [ ] Windows
  • [ ] Linux
  • [ ] Android
  • [ ] IOS
Hardware Requirements (graphics card, VR Device, ...)

All 8 comments

Check these examples:

Points sampled with .getSpacedPoints(): https://jsfiddle.net/rzkswgLo/
Points sampled with .getPoints(): https://jsfiddle.net/rzkswgLo/1/

If you open both examples in two tabs, you can easily see the different sampling. So basically the equidistant distribution of points computed via .getSpacedPoints() seems to work.

Can you provide a fiddle with your code?

If your curve is large you can try the following: After creating your curve object, set the __arcLengthDivisions to a high value:

curve.__arcLengthDivisions = 1000; // or even higher

This will improve the precision of the computation...

There is the example of problem
https://jsfiddle.net/rzkswgLo/2/

If your curve is large you can try the following: After creating your curve object, set the __arcLengthDivisions to a high value:

It helped a lot! Thank you man! :)

@Mugen87 that seems like something that should definitely be in the docs.

What is the meaning of the double underscore in __arcLengthDivisions?

I know it as meaning superprivate from python, does it have a conventional meaning in JS?

Was not aware of __arcLengthDivisions. Seems hacky indeed...

__arcLengthDivisions is only used in Curve .getLengths(). It basically controls the amount of segments a curve is separated into for calculating the overall length. This logic is mainly used in Curve .getUtoTmapping(). For most curves the default value of 200 is sufficient. But for large curves, this value can be too small. So __arcLengthDivisions is something like a backdoor that provides some flexibility 馃槈

And yes, the current implementation looks a bit hacky. Maybe it's better to create a setter and getter for arcLengthDivisions. In this way, we don't need the double underscore notation and have a public API for managing the value.

Was not aware of __arcLengthDivisions. Seems hacky indeed...

My apologies for my cowboy engineering back in the days... 馃槄

Was this page helpful?
0 / 5 - 0 ratings

Related issues

zsitro picture zsitro  路  3Comments

jlaquinte picture jlaquinte  路  3Comments

boyravikumar picture boyravikumar  路  3Comments

danieljack picture danieljack  路  3Comments

yqrashawn picture yqrashawn  路  3Comments