add support for tab additions in lathe mode

This commit is contained in:
Stewart Allen 2023-02-14 11:03:06 -05:00
commit c71786e56a
2 changed files with 28 additions and 2 deletions

View file

@ -62,7 +62,8 @@ class Topo4 {
this.zBottom = state.zBottom;
this.resolution = resolution;
this.vertices = widget.getGeoVertices().toShared();
this.vertices = widget.getGeoVertices();
this.tabverts = widget.getTabVertices();
this.tool = tool.generateProfile(resolution).profile;
this.maxo = tool.profileDim.maxo * resolution;
this.diam = tool.fluteDiameter();
@ -87,7 +88,7 @@ class Topo4 {
}
async slice(onupdate) {
const { vertices, resolution } = this;
const { vertices, resolution, tabverts } = this;
const range = this.range = { min: Infinity, max: -Infinity };
const box = this.box = new THREE.Box2();
@ -106,6 +107,15 @@ class Topo4 {
range.min -= this.diam / 2;
range.max += this.diam / 2;
// merge in tab vertices (so they don't affect slice range / dimensions)
for (let i=0, l=tabverts.length; i<l; i += 3) {
const x = tabverts[i];
const z = tabverts[i + 2];
tabverts[i] = z;
tabverts[i + 2] = x;
}
this.vertices = [].appendAll(vertices).appendAll(tabverts).toFloat32().toShared();
const shards = Math.ceil(Math.min(25, vertices.length / 27000));
const step = (range.max - range.min) / shards;

View file

@ -626,6 +626,22 @@ class Widget {
this.points = null;
}
getTabVertices() {
const vert = [];
if (this.anno && this.anno.tab) {
for (let tab of this.anno.tab) {
const { pos, dim, rot } = tab;
const box = new THREE.BoxGeometry(dim.x, dim.y, dim.z).toNonIndexed();
box.applyMatrix4(
new THREE.Matrix4().makeRotationFromQuaternion(rot)
);
box.translate(pos.x, pos.y, pos.z);
vert.appendAll(box.attributes.position.array);
}
}
return vert;
}
getGeoVertices(opt = {}) {
const { unroll, translate } = opt;
let geo = this.mesh.geometry;