add new render type
This commit is contained in:
parent
4ca0a26af5
commit
cbc363d49f
5 changed files with 79 additions and 15 deletions
|
|
@ -3,18 +3,29 @@
|
|||
"use strict";
|
||||
|
||||
(function() {
|
||||
const KIRI = self.kiri, BASE = self.base, POLY = BASE.polygons;
|
||||
|
||||
class Render {
|
||||
constructor() {
|
||||
this.layers = {};
|
||||
}
|
||||
|
||||
setLayer(layer, color) {
|
||||
setLayer(layer, colors) {
|
||||
let layers = this.layers;
|
||||
if (typeof(colors) === 'number') {
|
||||
colors = {
|
||||
line: color,
|
||||
face: color
|
||||
};
|
||||
}
|
||||
this.current = layers[layer] = layers[layer] || {
|
||||
lines: [],
|
||||
polys: [],
|
||||
faces: [],
|
||||
color: color || 0
|
||||
color: colors || {
|
||||
line: 0,
|
||||
face: 0
|
||||
}
|
||||
};
|
||||
return this;
|
||||
}
|
||||
|
|
@ -44,6 +55,33 @@
|
|||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
addFlat(polys, options) {
|
||||
let opts = options || {};
|
||||
let offset = opts.offset || 1;
|
||||
if (Array.isArray(polys)) {
|
||||
polys = POLY.flatten(polys, [], true);
|
||||
} else {
|
||||
polys = POLY.flatten([polys], [], true);
|
||||
}
|
||||
if (!polys.length) {
|
||||
return;
|
||||
}
|
||||
const z = polys[0].getZ(), faces = this.current.faces;
|
||||
polys.forEach(poly => {
|
||||
let exp = [];
|
||||
POLY.offset([poly], offset/2, { z, outs: exp, flat: true });
|
||||
POLY.offset([poly], -offset/2, { z, outs: exp, flat: true });
|
||||
if (opts.outline) {
|
||||
this.addPolys(exp.clone());
|
||||
}
|
||||
POLY.nest(exp).forEach((poly,i) => {
|
||||
poly.earcut().forEach(ep => {
|
||||
ep.forEachPoint(p => { faces.push(p.x, p.y, p.z) });
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
self.kiri.Render = Render;
|
||||
|
|
|
|||
Loading…
Reference in a new issue