You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
71 lines
1.9 KiB
71 lines
1.9 KiB
#pragma once
|
|
|
|
#include <real.hpp>
|
|
#include <utility>
|
|
#include <vec.hpp>
|
|
#include <line.hpp>
|
|
|
|
class ISolid {
|
|
public:
|
|
virtual ~ISolid() = default;
|
|
virtual real sdf(const Vec3 &p) = 0;
|
|
};
|
|
|
|
Vec2 get2DRepOf3DPt(const Vec3 &pt3D, const Vec3 &u, const Vec3 &v, const Vec3 &localO) {
|
|
Vec3 OP = pt3D - localO;
|
|
return {OP.dot(u), OP.dot(v)};
|
|
}
|
|
|
|
class IExtrudedSolid : public ISolid {
|
|
public:
|
|
Polyline _profile;
|
|
real _rScale;
|
|
public:
|
|
IExtrudedSolid(Polyline profile, real rScale) : _profile(std::move(profile)), _rScale(rScale) {
|
|
}
|
|
};
|
|
|
|
class ExtrudedSolidPolyline : public IExtrudedSolid {
|
|
private:
|
|
Polyline _axis;
|
|
Pt2Array _localProfile2D;
|
|
public:
|
|
ExtrudedSolidPolyline(Polyline profile, Polyline axis, real rScale) :
|
|
IExtrudedSolid(std::move(profile), rScale), _axis(std::move(axis)) {
|
|
// TODO: project profile at st point to 2D
|
|
Vec3 T = _axis.der1(0).normalize();
|
|
Vec3 N = _axis.der2(0).normalize();
|
|
Vec3 B = T.cross(N);
|
|
Vec3 Q = _axis.eval(0);
|
|
const Pt3Array& profilePts = _profile.getPoints();
|
|
for (int i = 0; i < profilePts.size(); ++i) {
|
|
const Vec3& P = profilePts[i];
|
|
Vec3 QP = P - Q;
|
|
auto uv = get2DRepOf3DPt(QP, N, B, Q);
|
|
// test it
|
|
{}
|
|
_localProfile2D.emplace_back(uv.x(), uv.y());
|
|
}
|
|
}
|
|
|
|
real sdf(const Vec3 &p) override {
|
|
ClosestDescOnSeg closestDesc = _axis.getClosestParam(p);
|
|
// TNB coordinate system
|
|
auto t = closestDesc.t;
|
|
Vec3 T = _axis.der1(t).normalize();
|
|
Vec3 N = _axis.der2(t).normalize();
|
|
Vec3 B = T.cross(N);
|
|
Vec3 Q = _axis.eval(t);
|
|
Vec3 QP = p - Q;
|
|
auto uv = get2DRepOf3DPt(QP, N, B, Q);
|
|
// test it
|
|
// TODO: to test if uv is in _localProfile2D
|
|
return 0;
|
|
}
|
|
};
|
|
|
|
class ExtrudedSolidPolynomialLine : public IExtrudedSolid {
|
|
protected:
|
|
PolynomialLine _axis;
|
|
|
|
};
|
|
|