lids for preview

This commit is contained in:
Val Erastov 2017-03-24 17:57:20 -07:00
parent 65117c184c
commit 7896483422
4 changed files with 32 additions and 5 deletions

View file

@ -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;
}

View file

@ -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) {

View file

@ -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];

View file

@ -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);
};