mirror of
https://github.com/xibyte/jsketcher
synced 2025-12-20 15:32:57 +01:00
refactor brep-builder
This commit is contained in:
parent
b59dfca014
commit
43b27d18c5
4 changed files with 35 additions and 12 deletions
|
|
@ -116,6 +116,12 @@ function addGlobalDebugActions(app) {
|
|||
AddCurve: (curve, color) => {
|
||||
__DEBUG__.AddPolyLine(curve.verb.tessellate().map(v => new Vector().set3(v)), 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);
|
||||
},
|
||||
HideSolids: () => {
|
||||
app.findAllSolidsOnScene().forEach(s => s.cadGroup.traverse(o => o.visible = false));
|
||||
app.viewer.render();
|
||||
|
|
|
|||
|
|
@ -17,7 +17,13 @@ export default function(face) {
|
|||
// tessy.gluTessProperty(libtess.gluEnum.GLU_TESS_WINDING_RULE, libtess.windingRule.GLU_TESS_WINDING_POSITIVE);
|
||||
tessy.gluTessCallback(libtess.gluEnum.GLU_TESS_VERTEX_DATA, vertexCallback);
|
||||
|
||||
tessy.gluTessNormal(0, 0, 1);
|
||||
const mirrored = isMirrored(face.surface);
|
||||
|
||||
if (mirrored) {
|
||||
tessy.gluTessNormal(0, 0, -1);
|
||||
} else {
|
||||
tessy.gluTessNormal(0, 0, 1);
|
||||
}
|
||||
|
||||
const params = [];
|
||||
tessy.gluTessBeginPolygon(params);
|
||||
|
|
@ -87,3 +93,10 @@ function analyzeCurvature(nurbs, triangles) {
|
|||
return triangles;
|
||||
|
||||
}
|
||||
|
||||
function isMirrored(surface) {
|
||||
let a = surface.point(0, 0);
|
||||
let b = surface.point(1, 0);
|
||||
let c = surface.point(1, 1);
|
||||
return b.minus(a).cross(c.minus(a))._normalize().dot(surface.normalUV(0, 0)) < 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ export function createPrism(basePoints, height) {
|
|||
basePath.add(NurbsCurve.createLinearNurbs(basePoints[i], basePoints[j]), basePoints[i], null);
|
||||
lidPath.add(NurbsCurve.createLinearNurbs(lidPoints[i], lidPoints[j]), lidPoints[i], null);
|
||||
}
|
||||
return enclose(basePath, lidPath, baseSurface, lidSurface, () => {});
|
||||
return enclose(basePath, lidPath, baseSurface, lidSurface);
|
||||
}
|
||||
|
||||
export function enclose(basePath, lidPath, basePlane, lidPlane) {
|
||||
|
|
@ -54,13 +54,10 @@ export function enclose(basePath, lidPath, basePlane, lidPlane) {
|
|||
|
||||
const walls = [];
|
||||
|
||||
const baseVertices = basePath.points.map(p => new Vertex(p));
|
||||
const lidVertices = lidPath.points.map(p => new Vertex(p));
|
||||
|
||||
const n = basePath.points.length;
|
||||
for (let i = 0; i < n; i++) {
|
||||
let j = (i + 1) % n;
|
||||
const wall = createWall(basePath.curves[i], lidPath.curves[i], baseVertices[j], baseVertices[i], lidVertices[i], lidVertices[j]);
|
||||
const wall = createWall(basePath.curves[i], lidPath.curves[i]);
|
||||
walls.push(wall);
|
||||
}
|
||||
return assemble(walls, basePlane, lidPlane)
|
||||
|
|
@ -85,14 +82,14 @@ function assemble(walls, basePlane, lidPlane) {
|
|||
let next = wallEdges[j];
|
||||
let wall = walls[i];
|
||||
|
||||
let baseEdge = new Edge(wall.isoCurveAlignU(0), curr.halfEdge1.vertexA, next.halfEdge1.vertexA);
|
||||
let lidEdge = new Edge(wall.isoCurveAlignU(1), curr.halfEdge1.vertexB, next.halfEdge1.vertexB);
|
||||
let baseEdge = new Edge(wall.isoCurveAlignU(1), curr.halfEdge1.vertexB, next.halfEdge1.vertexB);
|
||||
let lidEdge = new Edge(wall.isoCurveAlignU(0), curr.halfEdge1.vertexA, next.halfEdge1.vertexA);
|
||||
|
||||
baseEdges.push(baseEdge);
|
||||
lidEdges.push(lidEdge);
|
||||
|
||||
let wallFace = new Face(wall);
|
||||
wallFace.outerLoop.halfEdges.push(baseEdge.halfEdge2, curr.halfEdge1, lidEdge.halfEdge1, next.halfEdge2);
|
||||
wallFace.outerLoop.halfEdges.push(baseEdge.halfEdge2, curr.halfEdge2, lidEdge.halfEdge1, next.halfEdge1);
|
||||
wallFace.outerLoop.link();
|
||||
shell.faces.push(wallFace);
|
||||
}
|
||||
|
|
@ -320,12 +317,11 @@ function createBoundingNurbs(points, plane) {
|
|||
polygon = polygon.map(p => to3D._apply(p));
|
||||
|
||||
const nurbs = new NurbsSurface(new verb.geom.ExtrudedSurface(new verb.geom.Line(
|
||||
polygon[1].data(), polygon[0].data()), polygon[2].minus(polygon[1]).data()));
|
||||
polygon[0].data(), polygon[1].data()), polygon[2].minus(polygon[1]).data()));
|
||||
|
||||
return nurbs;
|
||||
}
|
||||
|
||||
|
||||
export function linkHalfEdges(edge, halfEdge1, halfEdge2) {
|
||||
halfEdge1.edge = edge;
|
||||
halfEdge2.edge = edge;
|
||||
|
|
@ -393,7 +389,7 @@ export function createWall(curve1, curve2) {
|
|||
if (bothClassOf(curve1, curve2, 'Line')) {
|
||||
throw 'unsupported'
|
||||
} else if (bothClassOf(curve1, curve2, 'NurbsCurve')) {
|
||||
return new NurbsSurface(verb.geom.NurbsSurface.byLoftingCurves([curve1.verb, curve2.verb], 1));
|
||||
return new NurbsSurface(verb.geom.NurbsSurface.byLoftingCurves([curve2.verb, curve1.verb], 1));
|
||||
} else {
|
||||
throw 'unsupported';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -114,6 +114,14 @@ export class NurbsSurface extends Surface {
|
|||
return normal;
|
||||
}
|
||||
|
||||
normalUV(u, v) {
|
||||
let normal = new Vector().set3(this.verb.normal(u, v));
|
||||
if (this.inverted) {
|
||||
normal._negate();
|
||||
}
|
||||
return normal;
|
||||
}
|
||||
|
||||
normalInMiddle(point) {
|
||||
let normal = new Vector().set3(this.verb.normal(0.5, 0.5));
|
||||
if (this.inverted) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue