flatten layer path encodings. became single element array a long time ago
This commit is contained in:
parent
ff789a3f60
commit
a753e12d3a
3 changed files with 41 additions and 45 deletions
|
|
@ -331,6 +331,7 @@ kiri.Layers.prototype.encode = function(state) {
|
|||
type: TYPE.LAYERS,
|
||||
layers: Object.keys(this.layers),
|
||||
data: Object.values(this.layers).map(layer => {
|
||||
const paths = layer.paths;
|
||||
return {
|
||||
// defaults
|
||||
off: layer.off,
|
||||
|
|
@ -343,14 +344,12 @@ kiri.Layers.prototype.encode = function(state) {
|
|||
norms: codec.allocFloat32Array(layer.norms, zeros),
|
||||
cface: layer.cface || codec.undef,
|
||||
// 3D lines
|
||||
paths: layer.paths.map(lp => {
|
||||
return {
|
||||
z: lp.z,
|
||||
index: lp.index,
|
||||
faces: codec.allocFloat32Array(lp.faces, zeros),
|
||||
norms: codec.allocFloat32Array(lp.norms, zeros)
|
||||
}
|
||||
}),
|
||||
paths: paths ? {
|
||||
z: paths.z,
|
||||
index: paths.index,
|
||||
faces: codec.allocFloat32Array(paths.faces, zeros),
|
||||
norms: codec.allocFloat32Array(paths.norms, zeros)
|
||||
} : undefined,
|
||||
cpath: layer.cpath || codec.undef
|
||||
}
|
||||
})
|
||||
|
|
@ -366,6 +365,7 @@ registerDecoder(TYPE.LAYERS, function(v, state) {
|
|||
|
||||
for (let i=0; i<layers.length; i++) {
|
||||
const data = v.data[i];
|
||||
const paths = data.paths;
|
||||
const d = render.layers[layers[i]] = {
|
||||
off: data.off,
|
||||
color: data.color,
|
||||
|
|
@ -374,14 +374,12 @@ registerDecoder(TYPE.LAYERS, function(v, state) {
|
|||
faces: codec.allocFloat32Array(data.faces),
|
||||
norms: codec.allocFloat32Array(data.norms),
|
||||
cface: data.cface,
|
||||
paths: data.paths.map(lp => {
|
||||
return {
|
||||
z: lp.z,
|
||||
index: lp.index,
|
||||
faces: codec.allocFloat32Array(lp.faces),
|
||||
norms: codec.allocFloat32Array(lp.norms)
|
||||
};
|
||||
}),
|
||||
paths: paths ? {
|
||||
z: paths.z,
|
||||
index: paths.index,
|
||||
faces: codec.allocFloat32Array(paths.faces),
|
||||
norms: codec.allocFloat32Array(paths.norms)
|
||||
} : undefined,
|
||||
cpath: data.cpath
|
||||
};
|
||||
// fixup null -> Infinity in material counts (JSON stringify sucks)
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ class Layers {
|
|||
faces: [], // triangles for areas and flats
|
||||
norms: undefined, // flats vertex normals
|
||||
cface: undefined, // flats face color indices
|
||||
paths: [], // 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
|
||||
color: colors || {
|
||||
check: 0,
|
||||
|
|
@ -216,7 +216,7 @@ class Layers {
|
|||
const z = opts.z || poly.getZ();
|
||||
const { faces, normals } = poly.toPath3D(offset, height, 0);
|
||||
const cur = this.current;
|
||||
const one = cur.paths[0];
|
||||
const one = cur.paths;
|
||||
if (one) {
|
||||
// merge all contour geometry for massive speed gain
|
||||
// todo: recode to concat all geometries at once, and not incrementally
|
||||
|
|
@ -242,7 +242,7 @@ class Layers {
|
|||
one.norms.appendAll(normals);
|
||||
}
|
||||
} else {
|
||||
cur.paths.push({ index: [], faces, z, norms: normals });
|
||||
cur.paths = { faces, z, norms: normals };
|
||||
if (opts.color) {
|
||||
cur.cpath = [ Object.assign({ start: 0, count: Infinity }, opts.color) ];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -186,7 +186,7 @@ class Stack {
|
|||
group.add(mesh);
|
||||
mats.appendAll(mat);
|
||||
}
|
||||
if (paths.length) {
|
||||
if (paths) {
|
||||
const mat = [];
|
||||
if (cpath) {
|
||||
cpath.forEach(c => { mat.push(newMat(c)) });
|
||||
|
|
@ -195,31 +195,29 @@ class Stack {
|
|||
}
|
||||
mat.forEach(m => m.visible = defstate);
|
||||
// const mat = newMat(data);
|
||||
paths.forEach((path, i) => {
|
||||
const { index, faces, norms, z, colors } = path;
|
||||
const geo = new THREE.BufferGeometry();
|
||||
geo.setAttribute('position', new THREE.BufferAttribute(faces, 3));
|
||||
if (index.length) {
|
||||
geo.setIndex(index);
|
||||
}
|
||||
if (norms) {
|
||||
geo.setAttribute('normal', new THREE.BufferAttribute(norms, 3));
|
||||
// geo.normalizeNormals();
|
||||
} else {
|
||||
geo.computeVertexNormals();
|
||||
}
|
||||
if (cpath) {
|
||||
cpath.forEach((c, i) => geo.addGroup(c.start, c.count, i));
|
||||
} else {
|
||||
geo.addGroup(0, Infinity, 0);
|
||||
}
|
||||
const mesh = new THREE.Mesh(geo, mat);
|
||||
mesh.position.z = z;
|
||||
// mesh.castShadow = true;
|
||||
// mesh.receiveShadow = true;
|
||||
meshes.push(mesh);
|
||||
group.add(mesh);
|
||||
});
|
||||
const { index, faces, norms, z, colors } = paths;
|
||||
const geo = new THREE.BufferGeometry();
|
||||
geo.setAttribute('position', new THREE.BufferAttribute(faces, 3));
|
||||
if (index && index.length) {
|
||||
geo.setIndex(index);
|
||||
}
|
||||
if (norms) {
|
||||
geo.setAttribute('normal', new THREE.BufferAttribute(norms, 3));
|
||||
// geo.normalizeNormals();
|
||||
} else {
|
||||
geo.computeVertexNormals();
|
||||
}
|
||||
if (cpath) {
|
||||
cpath.forEach((c, i) => geo.addGroup(c.start, c.count, i));
|
||||
} else {
|
||||
geo.addGroup(0, Infinity, 0);
|
||||
}
|
||||
const mesh = new THREE.Mesh(geo, mat);
|
||||
mesh.position.z = z;
|
||||
// mesh.castShadow = true;
|
||||
// mesh.receiveShadow = true;
|
||||
meshes.push(mesh);
|
||||
group.add(mesh);
|
||||
mats.appendAll(mat);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue