avoid rehydrating polygons and points for layer objects

This commit is contained in:
Stewart Allen 2022-10-15 19:09:51 -04:00
commit 6d3a52264b
3 changed files with 21 additions and 13 deletions

View file

@ -5,6 +5,7 @@ Full docs @ https://docs.grid.space/projects/kiri-moto
# Release 3.6 # Release 3.6
* improved FDM preview rendering speed and reduced memory usage
* threaded task and message passing performance improvements * threaded task and message passing performance improvements
* refactor FDM supports and synthetic widgets to use more common code * refactor FDM supports and synthetic widgets to use more common code
* allow FDM mixing of automatic and manual / detected supports * allow FDM mixing of automatic and manual / detected supports

View file

@ -365,6 +365,16 @@ registerDecoder(TYPE.POLY, function(v, state) {
// ----- Layers Codec ----- // ----- Layers Codec -----
function encodeLayerPolys(polys, state) {
return polys.map(poly => {
return {
open: poly.open,
color: poly.color,
points: codec.encodePointArray(poly.points, state.zeros)
}
});
}
kiri.Layers.prototype.encode = function(state) { kiri.Layers.prototype.encode = function(state) {
let zeros = state.zeros; let zeros = state.zeros;
let enc = { let enc = {
@ -377,7 +387,7 @@ kiri.Layers.prototype.encode = function(state) {
off: layer.off, off: layer.off,
color: layer.color, color: layer.color,
// 1D lines and polylines // 1D lines and polylines
polys: encode(layer.polys, state), polys: encodeLayerPolys(layer.polys, state),
lines: encodePointArray(layer.lines, state), lines: encodePointArray(layer.lines, state),
// 2D lines and flat areas // 2D lines and flat areas
faces: codec.allocFloat32Array(layer.faces, zeros), faces: codec.allocFloat32Array(layer.faces, zeros),
@ -409,8 +419,8 @@ registerDecoder(TYPE.LAYERS, function(v, state) {
const d = render.layers[layers[i]] = { const d = render.layers[layers[i]] = {
off: data.off, off: data.off,
color: data.color, color: data.color,
polys: decode(data.polys, state), polys: data.polys,
lines: decodePointArray(data.lines), lines: data.lines,
faces: codec.allocFloat32Array(data.faces), faces: codec.allocFloat32Array(data.faces),
norms: codec.allocFloat32Array(data.norms), norms: codec.allocFloat32Array(data.norms),
cface: data.cface, cface: data.cface,

View file

@ -89,15 +89,13 @@ class Stack {
renderLayer(layer, group) { renderLayer(layer, group) {
function addPoly(vertices, poly) { function addPoly(vertices, poly) {
const points = poly.points, len = points.length; const points = poly.points, len = points.length;
for (let i=1; i<len; i++) { for (let i=3; i<len; i += 3) {
const p1 = points[i-1], p2 = points[i]; vertices.push(new THREE.Vector3(points[i-3], points[i-2], points[i-1]));
vertices.push(new THREE.Vector3(p1.x, p1.y, p1.z)); vertices.push(new THREE.Vector3(points[i+0], points[i+1], points[i+2]));
vertices.push(new THREE.Vector3(p2.x, p2.y, p2.z));
} }
if (!poly.open) { if (!poly.open) {
const p1 = points[len - 1], p2 = points[0]; vertices.push(new THREE.Vector3(points[len-3], points[len-2], points[len-1]));
vertices.push(new THREE.Vector3(p1.x, p1.y, p1.z)); vertices.push(new THREE.Vector3(points[0], points[1], points[2]));
vertices.push(new THREE.Vector3(p2.x, p2.y, p2.z));
} }
} }
@ -134,9 +132,8 @@ class Stack {
} }
} }
// for now, line segments inherit the last color // for now, line segments inherit the last color
for (let i=0, il=lines.length; i<il; i++) { for (let i=0, il=lines.length; i<il; i += 3) {
const p = lines[i]; vert.push(new THREE.Vector3(lines[i], lines[i+1], lines[i+1]));
vert.push(new THREE.Vector3(p.x, p.y, p.z));
} }
// ensure at least one group using the default color settings // ensure at least one group using the default color settings
if (grp.length === 0) { if (grp.length === 0) {