mirror of
https://github.com/xibyte/jsketcher
synced 2025-12-10 10:25:36 +01:00
nurbs surface
This commit is contained in:
parent
c96a9f2b40
commit
84d8141165
9 changed files with 101 additions and 5 deletions
|
|
@ -51,6 +51,7 @@
|
|||
"json-loader": "0.5.4 ",
|
||||
"jquery": "2.1.0",
|
||||
"less": "2.7.1",
|
||||
"libtess": "1.2.2"
|
||||
"libtess": "1.2.2",
|
||||
"verb-nurbs": "2.0.2"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import {BREPValidator} from '../../../brep/brep-validator'
|
|||
import * as stitching from '../../../brep/stitching'
|
||||
import {subtract, union} from '../../../brep/operations/boolean'
|
||||
import {Loop} from '../../../brep/topo/loop'
|
||||
import {Line} from '../../../brep/geom/impl/line'
|
||||
import {Shell} from '../../../brep/topo/shell'
|
||||
import {CompositeCurve} from '../../../brep/geom/curve'
|
||||
import {ReadSketchContoursFromFace} from '../sketch/sketch-reader'
|
||||
|
|
@ -103,17 +104,28 @@ export function getEncloseDetails(params, contours, sketchSurface, invert, force
|
|||
const lidPath = new CompositeCurve();
|
||||
|
||||
let lidPoints = basePath.points;
|
||||
if (!math.equal(params.prism, 1)) {
|
||||
var applyPrism = !math.equal(params.prism, 1);
|
||||
if (applyPrism) {
|
||||
const _3D = sketchSurface.get3DTransformation();
|
||||
const _2D = _3D.invert();
|
||||
lidPoints = math.polygonOffset(lidPoints.map(p => _2D.apply(p)) , params.prism).map(p => _3D._apply(p));
|
||||
lidPoints = math.polygonOffset(lidPoints.map(p => _2D.apply(p)) , params.prism).map(p => _3D._apply(p));
|
||||
}
|
||||
|
||||
lidPoints = lidPoints.map(p => p.plus(target));
|
||||
for (let i = 0; i < basePath.points.length; ++i) {
|
||||
const curve = basePath.curves[i];
|
||||
const point = lidPoints[i];
|
||||
const group = basePath.groups[i];
|
||||
lidPath.add(curve.translate(target), point.plus(target), group);
|
||||
let lidCurve;
|
||||
if (curve.isLine) {
|
||||
//TODO: breaks test_TR_OUT_TR_INNER
|
||||
lidCurve = Line.fromSegment(point, lidPoints[(i + 1) % lidPoints.length]);
|
||||
} else {
|
||||
lidCurve = curve.translate(target);
|
||||
if (applyPrism) {
|
||||
lidCurve = lidCurve.offset(params.prism);
|
||||
}
|
||||
}
|
||||
lidPath.add(lidCurve, point, group);
|
||||
}
|
||||
|
||||
const lidSurface = baseSurface.translate(target).invert();
|
||||
|
|
|
|||
|
|
@ -1,9 +1,12 @@
|
|||
import {CompositeCurve} from '../../../brep/geom/curve'
|
||||
import {ApproxCurve} from '../../../brep/geom/impl/approx'
|
||||
import {NurbsCurve} from '../../../brep/geom/impl/nurbs'
|
||||
import {Point} from '../../../brep/geom/point'
|
||||
import {Line} from '../../../brep/geom/impl/Line'
|
||||
import {LUT} from '../../../math/bezier-cubic'
|
||||
import {isCCW} from '../../../math/math'
|
||||
import {AXIS} from '../../../math/l3space'
|
||||
import verb from 'verb-nurbs'
|
||||
|
||||
const RESOLUTION = 20;
|
||||
|
||||
|
|
@ -28,6 +31,19 @@ class SketchPrimitive {
|
|||
isCurve() {
|
||||
return this.constructor.name != 'Segment';
|
||||
}
|
||||
|
||||
toNurbs(plane, _3dtr) {
|
||||
const obj = this.inverted ? this.toInverted() : this;
|
||||
return obj.toNurbsImpl(plane, _3dtr);
|
||||
}
|
||||
|
||||
toNurbsImpl(plane, _3dtr) {
|
||||
throw 'not implemented'
|
||||
}
|
||||
|
||||
toInverted() {
|
||||
throw 'not implemented'
|
||||
}
|
||||
}
|
||||
|
||||
export class Segment extends SketchPrimitive {
|
||||
|
|
@ -76,6 +92,18 @@ export class Arc extends SketchPrimitive {
|
|||
points.push(bo);
|
||||
return points;
|
||||
}
|
||||
|
||||
toInverted() {
|
||||
return new Arc(-1, this.b, this.a, this.c);
|
||||
}
|
||||
|
||||
toNurbsImpl(plane, _3dtr) {
|
||||
const basis = plane.basis();
|
||||
const startAngle = Math.atan2(this.a.y - this.c.y, this.a.x - this.c.x);
|
||||
const endAngle = Math.atan2(this.b.y - this.c.y, this.b.x - this.c.x);
|
||||
const arcCurve = new verb.geom.Arc(_3dtr(this.c).toArray(), basis[0].toArray(), basis[1].toArray(), this.r, startAngle, endAngle);
|
||||
return new NurbsCurve(arcCurve);
|
||||
}
|
||||
}
|
||||
|
||||
export class BezierCurve extends SketchPrimitive {
|
||||
|
|
@ -180,6 +208,10 @@ export class Ellipse extends SketchPrimitive {
|
|||
const USE_APPROX_FOR = new Set();
|
||||
//USE_APPROX_FOR.add('Arc');
|
||||
|
||||
const USE_NURBS_FOR = new Set();
|
||||
USE_NURBS_FOR.add('Arc');
|
||||
|
||||
|
||||
export class Contour {
|
||||
|
||||
constructor() {
|
||||
|
|
@ -221,6 +253,9 @@ export class Contour {
|
|||
if (!forceApproximation && USE_APPROX_FOR.has(segment.constructor.name)) {
|
||||
cc.add(new ApproxCurve(approximation, segment), prev, segment);
|
||||
prev = approximation[n - 1];
|
||||
} else if (!forceApproximation && USE_NURBS_FOR.has(segment.constructor.name)) {
|
||||
cc.add(segment.toNurbs(surface, tr), prev, segment);
|
||||
prev = approximation[n - 1];
|
||||
} else {
|
||||
for (let i = 1; i < n; ++i) {
|
||||
const curr = approximation[i];
|
||||
|
|
|
|||
|
|
@ -5,12 +5,14 @@ import {Face} from './topo/face'
|
|||
import {HalfEdge, Edge} from './topo/edge'
|
||||
import {Line} from './geom/impl/line'
|
||||
import {ApproxCurve, ApproxSurface} from './geom/impl/approx'
|
||||
import {NurbsSurface} from './geom/impl/nurbs'
|
||||
import {Plane} from './geom/impl/plane'
|
||||
import {Point} from './geom/point'
|
||||
import {BasisForPlane, Matrix3} from '../math/l3space'
|
||||
import {CompositeCurve} from './geom/curve'
|
||||
import * as cad_utils from '../3d/cad-utils'
|
||||
import * as math from '../math/math'
|
||||
import verb from 'verb-nurbs'
|
||||
|
||||
function isCCW(points, normal) {
|
||||
const tr2d = new Matrix3().setBasis(BasisForPlane(normal)).invert();
|
||||
|
|
@ -214,6 +216,11 @@ export function createFaceFromTwoEdges(e1, e2) {
|
|||
if (bothClassOf(e1.edge.curve, e2.edge.curve, 'Line')) {
|
||||
const normal = cad_utils.normalOfCCWSeq(loop.halfEdges.map(e => e.vertexA.point));
|
||||
surface = createPlaneForLoop(normal, loop);
|
||||
} else if (bothClassOf(e1.edge.curve, e2.edge.curve, 'NurbsCurve')) {
|
||||
|
||||
const verbSurface = verb.geom.NurbsSurface.byLoftingCurves([e1.edge.curve.verb, e2.edge.curve.verb], 2);
|
||||
surface = new NurbsSurface(verbSurface);
|
||||
|
||||
} else if (bothClassOf(e1.edge.curve, e2.edge.curve, 'ApproxCurve')) {
|
||||
|
||||
const chunk1 = e1.edge.curve.getChunk(e1.vertexA.point, e1.vertexB.point);
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
export class Curve {
|
||||
|
||||
constructor() {
|
||||
this.isLine = false;
|
||||
}
|
||||
|
||||
intersectCurve(curve) {
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ export class Line extends Curve {
|
|||
|
||||
constructor(p0, v) {
|
||||
super();
|
||||
this.isLine = true;
|
||||
this.p0 = p0;
|
||||
this.v = v;
|
||||
this._pointsCache = new Map();
|
||||
|
|
@ -51,6 +52,8 @@ export class Line extends Curve {
|
|||
|
||||
approximate(resolution, from, to, path) {
|
||||
}
|
||||
|
||||
offset() {};
|
||||
}
|
||||
|
||||
Line.fromTwoPlanesIntersection = function(plane1, plane2) {
|
||||
|
|
|
|||
22
web/app/brep/geom/impl/nurbs.js
Normal file
22
web/app/brep/geom/impl/nurbs.js
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
import verb from 'verb-nurbs'
|
||||
import {Matrix3} from '../../../math/l3space'
|
||||
|
||||
export class NurbsCurve {
|
||||
|
||||
constructor(verbCurve) {
|
||||
this.verb = verbCurve;
|
||||
}
|
||||
|
||||
translate(vector) {
|
||||
const tr = new Matrix3().translate(vector.x, vector.y, vector.z).toArray();
|
||||
return new NurbsCurve(this.verb.transform(tr));
|
||||
}
|
||||
}
|
||||
|
||||
export class NurbsSurface {
|
||||
|
||||
constructor(verbSurface) {
|
||||
this.verb = verbSurface;
|
||||
}
|
||||
|
||||
}
|
||||
7
web/app/brep/geom/impl/uv.js
Normal file
7
web/app/brep/geom/impl/uv.js
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
export class UV {
|
||||
|
||||
constructor(u, v) {
|
||||
this.u = u;
|
||||
this.v = v;
|
||||
}
|
||||
}
|
||||
|
|
@ -73,6 +73,14 @@ Matrix3.prototype.setMatrix = function(m) {
|
|||
return this;
|
||||
};
|
||||
|
||||
Matrix3.prototype.toArray = function() {
|
||||
return [
|
||||
[this.mxx, this.mxy, this.mxz, this.tx],
|
||||
[this.myx, this.myy, this.myz, this.ty],
|
||||
[this.mzx, this.mzy, this.mzz, this.tz]
|
||||
];
|
||||
};
|
||||
|
||||
Matrix3.prototype.invert = function() {
|
||||
|
||||
var det =
|
||||
|
|
|
|||
Loading…
Reference in a new issue