Skip to content

Commit

Permalink
resolve #266
Browse files Browse the repository at this point in the history
  • Loading branch information
markaren committed Jun 24, 2024
1 parent 18486d4 commit 50374db
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 18 deletions.
20 changes: 8 additions & 12 deletions include/threepp/extras/core/Curve.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,22 +91,18 @@ namespace threepp {
mutable std::vector<float> cacheArcLengths;
};

struct FrenetFrames {

typedef Curve<Vector2> Curve2;

class Curve3: public Curve<Vector3> {

public:
struct FrenetFrames {
std::vector<Vector3> tangents;
std::vector<Vector3> normals;
std::vector<Vector3> binormals;

std::vector<Vector3> tangents;
std::vector<Vector3> normals;
std::vector<Vector3> binormals;
};

FrenetFrames computeFrenetFrames(unsigned int segments, bool closed);
static FrenetFrames compute(const Curve<Vector3>& curve, unsigned int segments, bool closed);
};

typedef Curve<Vector2> Curve2;
typedef Curve<Vector3> Curve3;

extern template class threepp::Curve<Vector2>;
extern template class threepp::Curve<Vector3>;

Expand Down
2 changes: 1 addition & 1 deletion include/threepp/geometries/TubeGeometry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ namespace threepp {
bool closed = false);

private:
Curve3::FrenetFrames frames;
FrenetFrames frames;

TubeGeometry(std::shared_ptr<Curve3> path, const Params& params);
};
Expand Down
4 changes: 2 additions & 2 deletions src/threepp/extras/core/Curve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ void Curve<T>::getTangentAt(float u, T& optionalTarget) const {
this->getTangent(t, optionalTarget);
}

Curve3::FrenetFrames Curve3::computeFrenetFrames(unsigned int segments, bool closed) {
FrenetFrames FrenetFrames::compute(const Curve<Vector3>& curve, unsigned int segments, bool closed) {

// see http://www.cs.indiana.edu/pub/techreports/TR425.pdf

Expand All @@ -210,7 +210,7 @@ Curve3::FrenetFrames Curve3::computeFrenetFrames(unsigned int segments, bool clo
const float u = static_cast<float>(i) / static_cast<float>(segments);

auto& tangent = tangents.emplace_back();
this->getTangentAt(u, tangent);
curve.getTangentAt(u, tangent);
tangent.normalize();
}

Expand Down
4 changes: 2 additions & 2 deletions src/threepp/geometries/ExtrudeGeometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ ExtrudeGeometry::ExtrudeGeometry(const std::vector<Shape>& shapes, const Extrude

std::vector<Vector3> extrudePts;
bool extrudeByPath = false;
Curve3::FrenetFrames splineTube;
FrenetFrames splineTube;
Vector3 binormal, normal, position2;

if (extrudePath) {
Expand All @@ -281,7 +281,7 @@ ExtrudeGeometry::ExtrudeGeometry(const std::vector<Shape>& shapes, const Extrude

// TODO1 - have a .isClosed in spline?

splineTube = extrudePath->computeFrenetFrames(steps, false);
splineTube = FrenetFrames::compute(*extrudePath, steps, false);
}

// Safeguards if bevels are not enabled
Expand Down
2 changes: 1 addition & 1 deletion src/threepp/geometries/TubeGeometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ using namespace threepp;
TubeGeometry::TubeGeometry(std::shared_ptr<Curve3> path, const Params& params)
: path(std::move(path)), radius(params.radius) {

this->frames = this->path->computeFrenetFrames(params.tubularSegments, params.closed);
this->frames = FrenetFrames::compute(*this->path, params.tubularSegments, params.closed);

// helper variables

Expand Down

0 comments on commit 50374db

Please sign in to comment.