diff --git a/web/app/3d/craft/brep/wizards/cut-extrude.js b/web/app/3d/craft/brep/wizards/cut-extrude.js index 22d562ca..17893537 100644 --- a/web/app/3d/craft/brep/wizards/cut-extrude.js +++ b/web/app/3d/craft/brep/wizards/cut-extrude.js @@ -1,6 +1,8 @@ import {CURRENT_SELECTION as S} from './wizard' import {PreviewWizard, SketchBasedPreviewer} from './preview-wizard' import {ParametricExtruder, fixNegativeValue} from '../cut-extrude' +import {TriangulatePolygons} from '../../../triangulation' +import Vector from '../../../../math/vector' const METADATA = [ ['value' , 'number', 50], @@ -68,6 +70,11 @@ export class ExtrudePreviewer extends SketchBasedPreviewer { triangles.push([ base[p], base[q], lid[q] ]); triangles.push([ lid[q], lid[p], base[p] ]); } + TriangulatePolygons([base], baseNormal, (v) => v.toArray(), (arr) => new Vector().set3(arr)) + .forEach(tr => triangles.push(tr)); + + TriangulatePolygons([lid], lidNormal, (v) => v.toArray(), (arr) => new Vector().set3(arr)) + .forEach(tr => triangles.push(tr)); } return triangles; } diff --git a/web/app/3d/scene/brep-scene-object.js b/web/app/3d/scene/brep-scene-object.js index 674fbc0d..ef8f5c63 100644 --- a/web/app/3d/scene/brep-scene-object.js +++ b/web/app/3d/scene/brep-scene-object.js @@ -82,7 +82,7 @@ class BREPSceneFace extends SceneFace { } function triangulate(face) { - function csgVert(data) { + function v(data) { return new Vector(data[0], data[1], data[2]); } function data(v) { @@ -97,13 +97,12 @@ function triangulate(face) { let vertices = Triangulate(contours, data(face.surface.normal)); for (let i = 0; i < vertices.length; i += 3 ) { - var a = csgVert(vertices[i]); - var b = csgVert(vertices[i + 1]); - var c = csgVert(vertices[i + 2]); + var a = v(vertices[i]); + var b = v(vertices[i + 1]); + var c = v(vertices[i + 2]); triangled.push([a, b, c]); } return triangled; - } export function triangulateToThree(shell, geom) { diff --git a/web/app/3d/triangulation.js b/web/app/3d/triangulation.js index 52961c91..00be4338 100644 --- a/web/app/3d/triangulation.js +++ b/web/app/3d/triangulation.js @@ -65,6 +65,23 @@ export function Triangulate(contours, normal) { return triangleVerts; } +export function TriangulatePolygons(polygons, normal, toArray, fromArray) { + const triangled = []; + const contours = []; + for (let poly of polygons) { + contours.push(poly.map(point => toArray(point))); + } + + let vertices = Triangulate(contours, toArray(normal)); + for (let i = 0; i < vertices.length; i += 3 ) { + var a = fromArray(vertices[i]); + var b = fromArray(vertices[i + 1]); + var c = fromArray(vertices[i + 2]); + triangled.push([a, b, c]); + } + return triangled; +} + export function TriangulateFace(face) { function arr(v) { return [v.x, v.y, v.z]; diff --git a/web/app/math/vector.js b/web/app/math/vector.js index 3e216167..d82875f7 100644 --- a/web/app/math/vector.js +++ b/web/app/math/vector.js @@ -126,6 +126,10 @@ Vector.prototype.equals = function(vector) { return vectorsEqual(this, vector); }; +Vector.prototype.toArray = function() { + return [this.x, this.y, this.z]; +}; + Vector.prototype.three = function() { return new THREE.Vector3(this.x, this.y, this.z); };