markaren / threepp

C++20 port of three.js (r129)
MIT License
581 stars 50 forks source link

Create TubeGeometry from LineCurve3: build error #266

Closed skemaikin closed 2 weeks ago

skemaikin commented 2 weeks ago

HI! I'm trying to create TubeGeometry from LineCurve3.

std::vector<threepp::Vector3> points;
points.push_back({ 0, 0, 0 });
points.push_back({ 1, 1, 1 });
auto curve = std::make_shared<threepp::LineCurve3>(points[0], points[1]);
auto tube = threepp::TubeGeometry::create(curve);

I've got a building error:

[build] XXX/test.cpp: In function ‘void test()’:
[build] XXX/test.cpp:65:54: error: no matching function for call to ‘threepp::TubeGeometry::create(std::shared_ptr<threepp::LineCurveT<threepp::Vector3> >&)’
[build]    65 |             auto tube = threepp::TubeGeometry::create(curve);
[build]       |                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~

But , there is no building error when I'm trying to create TubeGeometry from CatmullRomCurve3.

markaren commented 2 weeks ago

Yeah, I see the issue. TubeGeometry expects a Curve3, but LineCurve3 is just a Curve<Vector3>. I think this was me trying to be clever using templates for that type so that I didn't have to duplicate code.. I need to think about this.

markaren commented 2 weeks ago

I made a fix, but can you say something about the usecase? Isn't this just a more complex CylinderGeometry?

skemaikin commented 2 weeks ago

I made a fix, but can you say something about the usecase? Isn't this just a more complex CylinderGeometry?

So fast! ))

  1. 266 fix works fine!
  2. CylinderGeometry doesn't have input points parameters, but I need to build tubes based on arbitrary plylines.
  3. I noticed that the TubeGeometry::create with CatmullRomCurve3 produces correct tubes even if they consist of two points. So I cleaned my code and now only use the CatmullRomCurve3.

Thanks!

markaren commented 2 weeks ago

Got it. I will keep the changes as it was an improvement on the API