work on getting index translated widget geometry
This commit is contained in:
parent
ad1b25416e
commit
2af361fc5a
8 changed files with 57 additions and 37 deletions
|
|
@ -1761,7 +1761,9 @@ function updateStock(args, event) {
|
||||||
|
|
||||||
const {x, y, z} = stock;
|
const {x, y, z} = stock;
|
||||||
if (x && y && z && !STACKS.getStack('bounds')) {
|
if (x && y && z && !STACKS.getStack('bounds')) {
|
||||||
const render = new kiri.Layers().setLayer('bounds', { face: 0xaaaaaa, line: 0xaaaaaa, index: currentIndex });
|
const render = new kiri.Layers()
|
||||||
|
.setRotation(currentIndex)
|
||||||
|
.setLayer('bounds', { face: 0xaaaaaa, line: 0xaaaaaa });
|
||||||
const stack = STACKS.setFreeMem(false).create('bounds', SPACE.world);
|
const stack = STACKS.setFreeMem(false).create('bounds', SPACE.world);
|
||||||
const hx = x/2, hy = y/2;
|
const hx = x/2, hy = y/2;
|
||||||
const sz = stock.z || 0;
|
const sz = stock.z || 0;
|
||||||
|
|
|
||||||
|
|
@ -1036,7 +1036,6 @@ class OpPocket extends CamOp {
|
||||||
}
|
}
|
||||||
function newSliceOut(z) {
|
function newSliceOut(z) {
|
||||||
let slice = newSlice(z);
|
let slice = newSlice(z);
|
||||||
addSlices(slice);
|
|
||||||
sliceOut.push(slice);
|
sliceOut.push(slice);
|
||||||
return slice;
|
return slice;
|
||||||
}
|
}
|
||||||
|
|
@ -1109,10 +1108,12 @@ class OpPocket extends CamOp {
|
||||||
progress(zpro, "pocket");
|
progress(zpro, "pocket");
|
||||||
}
|
}
|
||||||
zpro += zinc;
|
zpro += zinc;
|
||||||
|
addSlices(slice);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let surfaces = op.surfaces[widget.id] || [];
|
let surfaces = op.surfaces[widget.id] || [];
|
||||||
|
// let vert = widget.getGeoVertices(true,true).map(v => v.round(4));
|
||||||
let vert = widget.getVertices().array.map(v => v.round(4));
|
let vert = widget.getVertices().array.map(v => v.round(4));
|
||||||
let outline = [];
|
let outline = [];
|
||||||
let faces = CAM.surface_find(widget, surfaces);
|
let faces = CAM.surface_find(widget, surfaces);
|
||||||
|
|
|
||||||
|
|
@ -139,6 +139,7 @@ CAM.slice = function(settings, widget, onupdate, ondone) {
|
||||||
|
|
||||||
function setAxisIndex(degrees) {
|
function setAxisIndex(degrees) {
|
||||||
axisIndex = degrees;
|
axisIndex = degrees;
|
||||||
|
// state.axisIndex = (Math.PI / 180) * axisIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
function addSlices(slices) {
|
function addSlices(slices) {
|
||||||
|
|
@ -213,6 +214,18 @@ CAM.slice = function(settings, widget, onupdate, ondone) {
|
||||||
op.slice((progress, message) => {
|
op.slice((progress, message) => {
|
||||||
onupdate((opSum + (progress * weight)) / opTot, message || op.type());
|
onupdate((opSum + (progress * weight)) / opTot, message || op.type());
|
||||||
});
|
});
|
||||||
|
// setup new state when indexing the workspace
|
||||||
|
if (false && op.op.type === "index") {
|
||||||
|
let points = base.verticesToPoints(widget.getGeoVertices(true, true));
|
||||||
|
state.slicer = new kiri.cam_slicer(points, {
|
||||||
|
zlist: true,
|
||||||
|
zline: true,
|
||||||
|
nobucket: true // b/c negative Z when rotated
|
||||||
|
});
|
||||||
|
new CAM.OPS.shadow(state, { type: "shadow", silent: true }).slice(progress => {
|
||||||
|
console.log('reshadow', progress.round(3));
|
||||||
|
});
|
||||||
|
}
|
||||||
camOps.push(op);
|
camOps.push(op);
|
||||||
opSum += weight;
|
opSum += weight;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -131,8 +131,7 @@ class Slicer {
|
||||||
let bucketCount = Math.max(1, Math.ceil(zMax / (zSum / points.length)) - 1);
|
let bucketCount = Math.max(1, Math.ceil(zMax / (zSum / points.length)) - 1);
|
||||||
let zScale = this.zScale = 1 / (zMax / bucketCount);
|
let zScale = this.zScale = 1 / (zMax / bucketCount);
|
||||||
let buckets = this.buckets = [];
|
let buckets = this.buckets = [];
|
||||||
|
if (bucketCount > 1 && !this.options.nobucket) {
|
||||||
if (bucketCount > 1) {
|
|
||||||
// create empty buckets
|
// create empty buckets
|
||||||
for (let i = 0; i <= bucketCount + 1; i++) {
|
for (let i = 0; i <= bucketCount + 1; i++) {
|
||||||
buckets.push([]);
|
buckets.push([]);
|
||||||
|
|
|
||||||
|
|
@ -400,7 +400,8 @@ kiri.Layers.prototype.encode = function(state) {
|
||||||
faces: codec.allocFloat32Array(paths.faces, zeros),
|
faces: codec.allocFloat32Array(paths.faces, zeros),
|
||||||
norms: codec.allocFloat32Array(paths.norms, zeros)
|
norms: codec.allocFloat32Array(paths.norms, zeros)
|
||||||
} : undefined,
|
} : undefined,
|
||||||
cpath: layer.cpath || codec.undef
|
cpath: layer.cpath || codec.undef,
|
||||||
|
rotation: layer.rotation
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
@ -430,7 +431,8 @@ registerDecoder(TYPE.LAYERS, function(v, state) {
|
||||||
faces: codec.allocFloat32Array(paths.faces),
|
faces: codec.allocFloat32Array(paths.faces),
|
||||||
norms: codec.allocFloat32Array(paths.norms)
|
norms: codec.allocFloat32Array(paths.norms)
|
||||||
} : undefined,
|
} : undefined,
|
||||||
cpath: data.cpath
|
cpath: data.cpath,
|
||||||
|
rotation: data.rotation
|
||||||
};
|
};
|
||||||
// fixup null -> Infinity in material counts (JSON stringify sucks)
|
// fixup null -> Infinity in material counts (JSON stringify sucks)
|
||||||
if (d.cface) {
|
if (d.cface) {
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,12 @@ class Layers {
|
||||||
return this.layers[layer];
|
return this.layers[layer];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// in radians
|
||||||
|
setRotation(x = 0, y = 0, z = 0) {
|
||||||
|
this.rotation = { x, y, z };
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
setLayer(layer, colors, off) {
|
setLayer(layer, colors, off) {
|
||||||
let layers = this.layers;
|
let layers = this.layers;
|
||||||
if (typeof(colors) === 'number') {
|
if (typeof(colors) === 'number') {
|
||||||
|
|
@ -50,6 +56,7 @@ class Layers {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
this.current = layers[layer] = layers[layer] || {
|
this.current = layers[layer] = layers[layer] || {
|
||||||
|
rotation: this.rotation,
|
||||||
off: off === true,
|
off: off === true,
|
||||||
lines: [],
|
lines: [],
|
||||||
polys: [], // colors are an attribute on polygons
|
polys: [], // colors are an attribute on polygons
|
||||||
|
|
@ -59,8 +66,7 @@ class Layers {
|
||||||
paths: undefined, // 3d extrusion / tube paths (used to be an array, now merged - FIX)
|
paths: undefined, // 3d extrusion / tube paths (used to be an array, now merged - FIX)
|
||||||
cpath: undefined, // path colors indices
|
cpath: undefined, // path colors indices
|
||||||
color: colors || {
|
color: colors || {
|
||||||
index: 0,
|
check: 0, // unused?
|
||||||
check: 0,
|
|
||||||
line: 0,
|
line: 0,
|
||||||
face: 0,
|
face: 0,
|
||||||
opacity: 1
|
opacity: 1
|
||||||
|
|
|
||||||
|
|
@ -106,8 +106,8 @@ class Stack {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const { polys, lines, faces, cface, paths, cpath, color, off, norms } = layer;
|
const { polys, lines, faces, cface, paths, cpath, color, off, norms, rotation } = layer;
|
||||||
const { index, opacity } = color;
|
const { opacity } = color;
|
||||||
const meshes = [];
|
const meshes = [];
|
||||||
const defstate = !off;
|
const defstate = !off;
|
||||||
const mats = [];
|
const mats = [];
|
||||||
|
|
@ -155,7 +155,7 @@ class Stack {
|
||||||
}
|
}
|
||||||
geo.setFromPoints(vert);
|
geo.setFromPoints(vert);
|
||||||
const segs = new THREE.LineSegments(geo, mat);
|
const segs = new THREE.LineSegments(geo, mat);
|
||||||
if (index) segs.rotation.x = index;
|
if (rotation) segs.rotation.x = rotation.x;
|
||||||
meshes.push(segs);
|
meshes.push(segs);
|
||||||
group.add(segs);
|
group.add(segs);
|
||||||
mats.appendAll(mat);
|
mats.appendAll(mat);
|
||||||
|
|
@ -186,7 +186,7 @@ class Stack {
|
||||||
geo.addGroup(0, Infinity, 0);
|
geo.addGroup(0, Infinity, 0);
|
||||||
}
|
}
|
||||||
const mesh = new THREE.Mesh(geo, mat);
|
const mesh = new THREE.Mesh(geo, mat);
|
||||||
if (index) mesh.rotation.x = index;
|
if (rotation) mesh.rotation.x = rotation.x;
|
||||||
// mesh.castShadow = true;
|
// mesh.castShadow = true;
|
||||||
// mesh.receiveShadow = true;
|
// mesh.receiveShadow = true;
|
||||||
meshes.push(mesh);
|
meshes.push(mesh);
|
||||||
|
|
@ -221,7 +221,7 @@ class Stack {
|
||||||
}
|
}
|
||||||
const mesh = new THREE.Mesh(geo, mat);
|
const mesh = new THREE.Mesh(geo, mat);
|
||||||
mesh.position.z = z;
|
mesh.position.z = z;
|
||||||
if (index) mesh.rotation.x = index;
|
if (rotation) mesh.rotation.x = rotation.x;
|
||||||
// mesh.castShadow = true;
|
// mesh.castShadow = true;
|
||||||
// mesh.receiveShadow = true;
|
// mesh.receiveShadow = true;
|
||||||
meshes.push(mesh);
|
meshes.push(mesh);
|
||||||
|
|
|
||||||
|
|
@ -649,40 +649,37 @@ class Widget {
|
||||||
this.points = null;
|
this.points = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
getGeoVertices(unroll) {
|
getGeoVertices(unroll, index) {
|
||||||
let geo = this.mesh.geometry;
|
let geo = this.mesh.geometry;
|
||||||
let pos = geo.getAttribute('position').array;
|
let pos = geo.getAttribute('position');
|
||||||
|
// if indexed, return points rotated about X and then offset
|
||||||
|
let track = this.track;
|
||||||
|
if (index && track.indexed) {
|
||||||
|
let delta = track.delta;
|
||||||
|
pos = pos.clone().applyMatrix4(
|
||||||
|
new THREE.Matrix4().makeRotationX(track.indexRad)
|
||||||
|
).applyMatrix4(
|
||||||
|
new THREE.Matrix4().makeTranslation(0, -delta.y, -delta.z + track.tzoff)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
pos = pos.array;
|
||||||
if (geo.index && unroll !== false) {
|
if (geo.index && unroll !== false) {
|
||||||
let idx = geo.index.array;
|
let idx = geo.index.array;
|
||||||
let len = idx.length;
|
let len = idx.length;
|
||||||
let p2 = new Float32Array(len * 3);
|
let pp2 = new Float32Array(len * 3);
|
||||||
let inc = 0;
|
let inc = 0;
|
||||||
for (let i=0; i<len; i++) {
|
for (let i=0; i<len; i++) {
|
||||||
let iv = idx[i];
|
let iv = idx[i];
|
||||||
let ip = iv * 3;
|
let ip = iv * 3;
|
||||||
p2[inc++] = pos[ip++];
|
pp2[inc++] = pos[ip++];
|
||||||
p2[inc++] = pos[ip++];
|
pp2[inc++] = pos[ip++];
|
||||||
p2[inc++] = pos[ip];
|
pp2[inc++] = pos[ip];
|
||||||
}
|
}
|
||||||
return p2;
|
pos = pp2;
|
||||||
} else {
|
} else if (index) {
|
||||||
return pos;
|
pos = pos.slice();
|
||||||
}
|
}
|
||||||
}
|
return pos;
|
||||||
|
|
||||||
iterPoints() {
|
|
||||||
let verts = this.getGeoVertices();
|
|
||||||
let index = 0;
|
|
||||||
let count = verts.length;
|
|
||||||
return new class ITER {
|
|
||||||
[Symbol.iterator]() { return {
|
|
||||||
next: () => {
|
|
||||||
let done = index >= count;
|
|
||||||
return done ? { done } :
|
|
||||||
{ value: newPoint(verts[index++], verts[index++], verts[index++]) };
|
|
||||||
}
|
|
||||||
} }
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getPoints() {
|
getPoints() {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue