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;
|
||||
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 hx = x/2, hy = y/2;
|
||||
const sz = stock.z || 0;
|
||||
|
|
|
|||
|
|
@ -1036,7 +1036,6 @@ class OpPocket extends CamOp {
|
|||
}
|
||||
function newSliceOut(z) {
|
||||
let slice = newSlice(z);
|
||||
addSlices(slice);
|
||||
sliceOut.push(slice);
|
||||
return slice;
|
||||
}
|
||||
|
|
@ -1109,10 +1108,12 @@ class OpPocket extends CamOp {
|
|||
progress(zpro, "pocket");
|
||||
}
|
||||
zpro += zinc;
|
||||
addSlices(slice);
|
||||
}
|
||||
}
|
||||
}
|
||||
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 outline = [];
|
||||
let faces = CAM.surface_find(widget, surfaces);
|
||||
|
|
|
|||
|
|
@ -139,6 +139,7 @@ CAM.slice = function(settings, widget, onupdate, ondone) {
|
|||
|
||||
function setAxisIndex(degrees) {
|
||||
axisIndex = degrees;
|
||||
// state.axisIndex = (Math.PI / 180) * axisIndex;
|
||||
}
|
||||
|
||||
function addSlices(slices) {
|
||||
|
|
@ -213,6 +214,18 @@ CAM.slice = function(settings, widget, onupdate, ondone) {
|
|||
op.slice((progress, message) => {
|
||||
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);
|
||||
opSum += weight;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -131,8 +131,7 @@ class Slicer {
|
|||
let bucketCount = Math.max(1, Math.ceil(zMax / (zSum / points.length)) - 1);
|
||||
let zScale = this.zScale = 1 / (zMax / bucketCount);
|
||||
let buckets = this.buckets = [];
|
||||
|
||||
if (bucketCount > 1) {
|
||||
if (bucketCount > 1 && !this.options.nobucket) {
|
||||
// create empty buckets
|
||||
for (let i = 0; i <= bucketCount + 1; i++) {
|
||||
buckets.push([]);
|
||||
|
|
|
|||
|
|
@ -400,7 +400,8 @@ kiri.Layers.prototype.encode = function(state) {
|
|||
faces: codec.allocFloat32Array(paths.faces, zeros),
|
||||
norms: codec.allocFloat32Array(paths.norms, zeros)
|
||||
} : 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),
|
||||
norms: codec.allocFloat32Array(paths.norms)
|
||||
} : undefined,
|
||||
cpath: data.cpath
|
||||
cpath: data.cpath,
|
||||
rotation: data.rotation
|
||||
};
|
||||
// fixup null -> Infinity in material counts (JSON stringify sucks)
|
||||
if (d.cface) {
|
||||
|
|
|
|||
|
|
@ -40,6 +40,12 @@ class Layers {
|
|||
return this.layers[layer];
|
||||
}
|
||||
|
||||
// in radians
|
||||
setRotation(x = 0, y = 0, z = 0) {
|
||||
this.rotation = { x, y, z };
|
||||
return this;
|
||||
}
|
||||
|
||||
setLayer(layer, colors, off) {
|
||||
let layers = this.layers;
|
||||
if (typeof(colors) === 'number') {
|
||||
|
|
@ -50,6 +56,7 @@ class Layers {
|
|||
};
|
||||
}
|
||||
this.current = layers[layer] = layers[layer] || {
|
||||
rotation: this.rotation,
|
||||
off: off === true,
|
||||
lines: [],
|
||||
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)
|
||||
cpath: undefined, // path colors indices
|
||||
color: colors || {
|
||||
index: 0,
|
||||
check: 0,
|
||||
check: 0, // unused?
|
||||
line: 0,
|
||||
face: 0,
|
||||
opacity: 1
|
||||
|
|
|
|||
|
|
@ -106,8 +106,8 @@ class Stack {
|
|||
}
|
||||
}
|
||||
|
||||
const { polys, lines, faces, cface, paths, cpath, color, off, norms } = layer;
|
||||
const { index, opacity } = color;
|
||||
const { polys, lines, faces, cface, paths, cpath, color, off, norms, rotation } = layer;
|
||||
const { opacity } = color;
|
||||
const meshes = [];
|
||||
const defstate = !off;
|
||||
const mats = [];
|
||||
|
|
@ -155,7 +155,7 @@ class Stack {
|
|||
}
|
||||
geo.setFromPoints(vert);
|
||||
const segs = new THREE.LineSegments(geo, mat);
|
||||
if (index) segs.rotation.x = index;
|
||||
if (rotation) segs.rotation.x = rotation.x;
|
||||
meshes.push(segs);
|
||||
group.add(segs);
|
||||
mats.appendAll(mat);
|
||||
|
|
@ -186,7 +186,7 @@ class Stack {
|
|||
geo.addGroup(0, Infinity, 0);
|
||||
}
|
||||
const mesh = new THREE.Mesh(geo, mat);
|
||||
if (index) mesh.rotation.x = index;
|
||||
if (rotation) mesh.rotation.x = rotation.x;
|
||||
// mesh.castShadow = true;
|
||||
// mesh.receiveShadow = true;
|
||||
meshes.push(mesh);
|
||||
|
|
@ -221,7 +221,7 @@ class Stack {
|
|||
}
|
||||
const mesh = new THREE.Mesh(geo, mat);
|
||||
mesh.position.z = z;
|
||||
if (index) mesh.rotation.x = index;
|
||||
if (rotation) mesh.rotation.x = rotation.x;
|
||||
// mesh.castShadow = true;
|
||||
// mesh.receiveShadow = true;
|
||||
meshes.push(mesh);
|
||||
|
|
|
|||
|
|
@ -649,41 +649,38 @@ class Widget {
|
|||
this.points = null;
|
||||
}
|
||||
|
||||
getGeoVertices(unroll) {
|
||||
getGeoVertices(unroll, index) {
|
||||
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) {
|
||||
let idx = geo.index.array;
|
||||
let len = idx.length;
|
||||
let p2 = new Float32Array(len * 3);
|
||||
let pp2 = new Float32Array(len * 3);
|
||||
let inc = 0;
|
||||
for (let i=0; i<len; i++) {
|
||||
let iv = idx[i];
|
||||
let ip = iv * 3;
|
||||
p2[inc++] = pos[ip++];
|
||||
p2[inc++] = pos[ip++];
|
||||
p2[inc++] = pos[ip];
|
||||
pp2[inc++] = pos[ip++];
|
||||
pp2[inc++] = pos[ip++];
|
||||
pp2[inc++] = pos[ip];
|
||||
}
|
||||
pos = pp2;
|
||||
} else if (index) {
|
||||
pos = pos.slice();
|
||||
}
|
||||
return p2;
|
||||
} else {
|
||||
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() {
|
||||
if (!this.points) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue