mirror of
https://github.com/xibyte/jsketcher
synced 2025-12-07 17:04:58 +01:00
use domain for parametric curves and surfaces instead assuming it's 0..1
This commit is contained in:
parent
321b161f72
commit
04eb798e49
7 changed files with 60 additions and 84 deletions
|
|
@ -53,8 +53,8 @@ export function enclose(basePath, lidPath, basePlane, lidPlane) {
|
|||
}
|
||||
|
||||
if (basePath.length === 1) {
|
||||
basePath = basePath[0].splitByParam(0.5);
|
||||
lidPath = lidPath[0].splitByParam(0.5);
|
||||
basePath = basePath[0].splitByParam(basePath[0].uMid);
|
||||
lidPath = lidPath[0].splitByParam(lidPath[0].uMid);
|
||||
}
|
||||
|
||||
const walls = [];
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ export default class BrepCurve {
|
|||
[uMin, uMax] = this.impl.domain();
|
||||
this.uMin = uMin;
|
||||
this.uMax = uMax;
|
||||
this.uMid = (uMax - uMin) * 0.5;
|
||||
}
|
||||
|
||||
translate(vector) {
|
||||
|
|
@ -48,23 +49,10 @@ export default class BrepCurve {
|
|||
}
|
||||
|
||||
splitByParam(u) {
|
||||
if (ueq(this.uMin) || ueq(this.uMax) || u < this.uMin || u > this.uMax) {
|
||||
if (ueq(u, this.uMin) || ueq(u, this.uMax) || u < this.uMin || u > this.uMax) {
|
||||
return null
|
||||
}
|
||||
let split = this.impl.split(u);
|
||||
|
||||
const splitCheck = (split) => {
|
||||
return (
|
||||
math.equal(this.impl.param(split[0].point(1)), this.impl.param(split[1].point(0))) &&
|
||||
math.equal(this.impl.param(split[0].point(0)), 0) &&
|
||||
math.equal(this.impl.param(split[0].point(1)), u) &&
|
||||
math.equal(this.impl.param(split[1].point(0)), u) &&
|
||||
math.equal(this.impl.param(split[1].point(1)), 1)
|
||||
)
|
||||
};
|
||||
if (!splitCheck(split)) {
|
||||
throw 'wrong split';
|
||||
}
|
||||
return split.map(v => new BrepCurve(v));
|
||||
|
||||
// return [
|
||||
|
|
@ -146,11 +134,16 @@ export default class BrepCurve {
|
|||
return new BrepCurve(this.impl.invert());
|
||||
}
|
||||
|
||||
startPoint() {
|
||||
return this.point(this.uMin);
|
||||
}
|
||||
|
||||
endPoint() {
|
||||
return this.point(this.uMax);
|
||||
}
|
||||
|
||||
middlePoint() {
|
||||
if (!this.__middlePoint) {
|
||||
this.__middlePoint = this.point(0.5);
|
||||
}
|
||||
return this.__middlePoint;
|
||||
return this.__middlePoint || (this.__middlePoint = this.point(this.uMid));
|
||||
}
|
||||
|
||||
passesThrough(point) {
|
||||
|
|
|
|||
|
|
@ -1,17 +1,11 @@
|
|||
import {BasisForPlane, Matrix3} from '../../../math/l3space'
|
||||
import * as math from '../../../math/math'
|
||||
import {Point} from '../point'
|
||||
import {Surface} from "../surface";
|
||||
import {Point} from '../point';
|
||||
import {Surface} from '../surface';
|
||||
import Vector from 'math/vector';
|
||||
import * as ext from "./nurbs-ext";
|
||||
import {EPSILON, eqEps, eqSqTol, TOLERANCE, TOLERANCE_SQ, ueq, veq, veq3, veqNeg} from "../tolerance";
|
||||
import curveIntersect from "./curve/curves-isec";
|
||||
import curveTess from "./curve/curve-tess";
|
||||
import {areEqual} from "../../../math/math";
|
||||
import {Plane} from "./plane";
|
||||
import BrepCurve from "../curves/brepCurve";
|
||||
import NurbsCurve from "../curves/nurbsCurve";
|
||||
import cache from "./cache";
|
||||
import * as ext from './nurbs-ext';
|
||||
import {Plane} from './plane';
|
||||
import BrepCurve from '../curves/brepCurve';
|
||||
import NurbsCurve from '../curves/nurbsCurve';
|
||||
import cache from './cache';
|
||||
|
||||
export class NurbsSurface extends Surface {
|
||||
|
||||
|
|
@ -19,34 +13,19 @@ export class NurbsSurface extends Surface {
|
|||
super();
|
||||
let {min: uMin, max: uMax} = verbSurface.domainU();
|
||||
let {min: vMin, max: vMax} = verbSurface.domainV();
|
||||
|
||||
if (uMin !== 0 || uMax !== 1 || vMin !== 0 || vMax !== 1) {
|
||||
throw 'only normalized(0..1) parametrization is supported';
|
||||
}
|
||||
|
||||
Object.assign(this, {
|
||||
uMin, uMax, vMin, vMax,
|
||||
uMid: (uMax - uMin) * 0.5,
|
||||
vMid: (vMax - vMin) * 0.5
|
||||
});
|
||||
|
||||
this.data = verbSurface.asNurbs();
|
||||
this.verb = verbSurface;
|
||||
this.inverted = inverted === true;
|
||||
this.mirrored = NurbsSurface.isMirrored(this);
|
||||
this.simpleSurface = simpleSurface || figureOutSimpleSurface(this);
|
||||
}
|
||||
|
||||
domainU() {
|
||||
return this.verb.domainU();
|
||||
}
|
||||
|
||||
domainV() {
|
||||
return this.verb.domainV();
|
||||
}
|
||||
|
||||
middle() {
|
||||
let {min: uMin, max: uMax} = this.verb.domainU();
|
||||
let {min: vMin, max: vMax} = this.verb.domainV();
|
||||
return [
|
||||
(uMax - uMin) * 0.5,
|
||||
(vMax - vMin) * 0.5
|
||||
];
|
||||
}
|
||||
|
||||
toNurbs() {
|
||||
return this;
|
||||
|
|
@ -72,15 +51,28 @@ export class NurbsSurface extends Surface {
|
|||
}
|
||||
|
||||
normalInMiddle() {
|
||||
//TODO: use domain!
|
||||
return this.normalUV(0.5, 0.5);
|
||||
return this.normalUV(this.uMid, this.vMid);
|
||||
}
|
||||
|
||||
pointInMiddle() {
|
||||
//TODO: use domain!
|
||||
return this.point(0.5, 0.5);
|
||||
return this.point(this.uMid, this.vMid);
|
||||
}
|
||||
|
||||
southWestPoint() {
|
||||
return this.point(this.uMin, this.vMin);
|
||||
}
|
||||
|
||||
southEastPoint() {
|
||||
return this.point(this.uMax, this.vMin);
|
||||
}
|
||||
|
||||
northEastPoint() {
|
||||
return this.point(this.uMax, this.vMax);
|
||||
}
|
||||
|
||||
northWestPoint() {
|
||||
return this.point(this.uMin, this.vMax);
|
||||
}
|
||||
|
||||
param(point) {
|
||||
return this.verb.closestParam(point.data());
|
||||
|
|
@ -115,13 +107,11 @@ export class NurbsSurface extends Surface {
|
|||
}
|
||||
|
||||
static isMirrored(surface) {
|
||||
let {min: uMin} = surface.domainU();
|
||||
let {min: vMin} = surface.domainV();
|
||||
|
||||
let x = surface.isoCurveAlignU(uMin).tangentAtParam(uMin);
|
||||
let y = surface.isoCurveAlignV(vMin).tangentAtParam(vMin);
|
||||
let x = surface.isoCurveAlignU(surface.uMin).tangentAtParam(surface.uMin);
|
||||
let y = surface.isoCurveAlignV(surface.vMin).tangentAtParam(surface.vMin);
|
||||
|
||||
return x.cross(y).dot(surface.normalUV(uMin, vMin)) < 0;
|
||||
return x.cross(y).dot(surface.normalUV(surface.uMin, surface.vMin)) < 0;
|
||||
}
|
||||
|
||||
intersectSurfaceForSameClass(other) {
|
||||
|
|
@ -130,7 +120,7 @@ export class NurbsSurface extends Surface {
|
|||
if (inverted) {
|
||||
curves = curves.map(curve => ext.curveInvert(curve));
|
||||
}
|
||||
curves.forEach(curve => ext.normalizeCurveParametrizationIfNeeded(curve))
|
||||
curves.forEach(curve => ext.normalizeCurveParametrizationIfNeeded(curve));
|
||||
return curves.map(curve => new BrepCurve(new NurbsCurve(newVerbCurve(curve))));
|
||||
}
|
||||
|
||||
|
|
@ -151,10 +141,6 @@ export class NurbsSurface extends Surface {
|
|||
isoCurveAlignV(param) {
|
||||
return this.isoCurve(param, false);
|
||||
}
|
||||
|
||||
intersectWithCurve(curve) {
|
||||
return verb.geom.Intersect.curveAndSurface(curve.impl.verb, this.verb, TOLERANCE).map(({uv}) => uv);
|
||||
}
|
||||
|
||||
tangentPlane(u, v) {
|
||||
let normal = this.normalUV(u, v);
|
||||
|
|
@ -162,7 +148,7 @@ export class NurbsSurface extends Surface {
|
|||
}
|
||||
|
||||
tangentPlaneInMiddle() {
|
||||
return this.tangentPlane(0.5, 0.5);
|
||||
return this.tangentPlane(this.uMid, this.vMid);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -189,8 +175,7 @@ verb.eval.Tess.rationalSurfaceAdaptive = function(surface, opts) {
|
|||
|
||||
function figureOutSimpleSurface(nurbs) {
|
||||
if (ext.surfaceMaxDegree(nurbs.data) === 1) {
|
||||
//TODO: use domain!
|
||||
return nurbs.tangentPlane(0.5, 0.5);
|
||||
return nurbs.tangentPlane(nurbs.uMid, nurbs.vMid);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
@ -628,9 +628,8 @@ function intersectEdges(shell1, shell2) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
function fixCurveDirection(curve, surface1, surface2, operationType) {
|
||||
let point = curve.point(0.5);
|
||||
let point = curve.middlePoint();
|
||||
let tangent = curve.tangentAtPoint(point);
|
||||
let normal1 = surface1.normal(point);
|
||||
let normal2 = surface2.normal(point);
|
||||
|
|
@ -883,10 +882,10 @@ function split(nodes, curve, result, faceA, faceB) {
|
|||
let edgeCurve = curve;
|
||||
let vertexA = inNode.vertex();
|
||||
let vertexB = node.vertex();
|
||||
if (!ueq(inNode.u, 0)) {
|
||||
if (!ueq(inNode.u, curve.uMin)) {
|
||||
[,edgeCurve] = edgeCurve.split(vertexA.point);
|
||||
}
|
||||
if (!ueq(node.u, 1)) {
|
||||
if (!ueq(node.u, curve.uMax)) {
|
||||
[edgeCurve] = edgeCurve.split(vertexB.point);
|
||||
}
|
||||
const edge = new Edge(edgeCurve, vertexA, vertexB);
|
||||
|
|
|
|||
|
|
@ -14,8 +14,8 @@ export class Edge extends TopoObject {
|
|||
}
|
||||
|
||||
static fromCurve(curve) {
|
||||
const a = new Vertex(curve.point(0));
|
||||
const b = new Vertex(curve.point(1));
|
||||
const a = new Vertex(curve.startPoint());
|
||||
const b = new Vertex(curve.endPoint());
|
||||
return new Edge(curve, a, b);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -149,17 +149,17 @@ function addGlobalDebugActions({viewer, cadScene, cadRegistry}) {
|
|||
__DEBUG__.AddPolyLine(curve.tessellate().map(p => new Vector().set3(p)), color);
|
||||
},
|
||||
AddNurbsCorners: (nurbs) => {
|
||||
__DEBUG__.AddPoint(nurbs.point(0, 0), 0xff0000);
|
||||
__DEBUG__.AddPoint(nurbs.point(1, 0), 0x00ff00);
|
||||
__DEBUG__.AddPoint(nurbs.point(1, 1), 0x0000ff);
|
||||
__DEBUG__.AddPoint(nurbs.point(0, 1), 0x00ffff);
|
||||
__DEBUG__.AddPoint(nurbs.southWestPoint(), 0xff0000);
|
||||
__DEBUG__.AddPoint(nurbs.southEastPoint(), 0x00ff00);
|
||||
__DEBUG__.AddPoint(nurbs.northEastPoint(), 0x0000ff);
|
||||
__DEBUG__.AddPoint(nurbs.northWestPoint(), 0x00ffff);
|
||||
},
|
||||
AddNormal: (atPoint, normal, color, scale) => {
|
||||
scale = scale || 100;
|
||||
__DEBUG__.AddSegment(atPoint, atPoint.plus(normal.multiply(scale)), color);
|
||||
},
|
||||
AddSurfaceNormal: (surface) => {
|
||||
__DEBUG__.AddNormal(surface.point(0.5, 0.5), surface.normalInMiddle());
|
||||
__DEBUG__.AddNormal(surface.pointInMiddle(), surface.normalInMiddle());
|
||||
},
|
||||
HideSolids: () => {
|
||||
cadRegistry.getAllShells().forEach(s => s.cadGroup.traverse(o => o.visible = false));
|
||||
|
|
|
|||
|
|
@ -132,8 +132,7 @@ export class SceneFace {
|
|||
}
|
||||
|
||||
let surface = this.surface();
|
||||
let [u, v] = surface.middle();
|
||||
const _3dTransformation = surface.tangentPlane(u, v).get3DTransformation();
|
||||
const _3dTransformation = surface.tangentPlaneInMiddle().get3DTransformation();
|
||||
const addSketchObjects = (sketchObjects, material, close) => {
|
||||
for (let sketchObject of sketchObjects) {
|
||||
let line = new THREE.Line(new THREE.Geometry(), material);
|
||||
|
|
|
|||
Loading…
Reference in a new issue