reflow fdm client ui events, fix paint on near vertical surfaces
This commit is contained in:
parent
edff2228f7
commit
a13bb79f4b
2 changed files with 116 additions and 149 deletions
|
|
@ -156,7 +156,7 @@ function addPaintOverlaySimple(material, paintPoints, paintColor = new THREE.Col
|
||||||
vec3 worldNormal = normalize(cross(posDx, posDy));
|
vec3 worldNormal = normalize(cross(posDx, posDy));
|
||||||
|
|
||||||
// Only paint downward-facing surfaces if option is enabled
|
// Only paint downward-facing surfaces if option is enabled
|
||||||
bool shouldPaint = !onlyDownwardFacing || worldNormal.z < 0.0;
|
bool shouldPaint = !onlyDownwardFacing || worldNormal.z < -0.001;
|
||||||
if (shouldPaint) {
|
if (shouldPaint) {
|
||||||
// Check if this fragment is within any paint sphere
|
// Check if this fragment is within any paint sphere
|
||||||
bool painted = false;
|
bool painted = false;
|
||||||
|
|
@ -302,7 +302,7 @@ function addPaintOverlayTexture(material, paintPoints, paintColor = new THREE.Co
|
||||||
vec3 worldNormal = normalize(cross(posDx, posDy));
|
vec3 worldNormal = normalize(cross(posDx, posDy));
|
||||||
|
|
||||||
// Only paint downward-facing surfaces if option is enabled
|
// Only paint downward-facing surfaces if option is enabled
|
||||||
bool shouldPaint = !onlyDownwardFacing || worldNormal.z < 0.0;
|
bool shouldPaint = !onlyDownwardFacing || worldNormal.z < -0.001;
|
||||||
if (shouldPaint) {
|
if (shouldPaint) {
|
||||||
bool painted = false;
|
bool painted = false;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@ import { api } from '../../app/api.js';
|
||||||
import { conf } from '../../app/conf/defaults.js';
|
import { conf } from '../../app/conf/defaults.js';
|
||||||
import { addPaintOverlayTexture, updatePaintOverlay } from '../../app/paint.js';
|
import { addPaintOverlayTexture, updatePaintOverlay } from '../../app/paint.js';
|
||||||
|
|
||||||
const { Matrix4, Vector3, BufferAttribute, BufferGeometryUtils, Raycaster, Euler } = THREE;
|
|
||||||
const { VIEWS } = api.const;
|
const { VIEWS } = api.const;
|
||||||
|
|
||||||
const LANG = api.language.current;
|
const LANG = api.language.current;
|
||||||
|
|
@ -16,7 +15,6 @@ let lastView,
|
||||||
removingSupports = false,
|
removingSupports = false,
|
||||||
isFdmMode = false,
|
isFdmMode = false,
|
||||||
alert = [],
|
alert = [],
|
||||||
func = {},
|
|
||||||
down;
|
down;
|
||||||
|
|
||||||
export function init() {
|
export function init() {
|
||||||
|
|
@ -80,6 +78,13 @@ export function init() {
|
||||||
ui.fdmRanges.innerHTML = '';
|
ui.fdmRanges.innerHTML = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function onEventFDM(topic, fn) {
|
||||||
|
return api.event.on(topic, function() {
|
||||||
|
if (!isFdmMode) return;
|
||||||
|
fn(...arguments);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// re-render ranges menu
|
// re-render ranges menu
|
||||||
function updateRanges(ranges = []) {
|
function updateRanges(ranges = []) {
|
||||||
let html = [];
|
let html = [];
|
||||||
|
|
@ -134,7 +139,7 @@ export function init() {
|
||||||
api.event.on("view.set", view => {
|
api.event.on("view.set", view => {
|
||||||
$('top-slider').style.display = 'none';
|
$('top-slider').style.display = 'none';
|
||||||
lastView = view;
|
lastView = view;
|
||||||
func.sdone();
|
supportDone();
|
||||||
// let ranges = api.conf.get().process.ranges;
|
// let ranges = api.conf.get().process.ranges;
|
||||||
if (isFdmMode) {
|
if (isFdmMode) {
|
||||||
if (lastView === VIEWS.SLICE) {
|
if (lastView === VIEWS.SLICE) {
|
||||||
|
|
@ -164,155 +169,30 @@ export function init() {
|
||||||
|
|
||||||
api.event.on("button.click", target => {
|
api.event.on("button.click", target => {
|
||||||
switch (target) {
|
switch (target) {
|
||||||
case api.ui.ssaGen: return func.sgen();
|
case api.ui.ssmAdd: return supportStart({ remove: false });
|
||||||
case api.ui.ssmAdd: return func.sadd({ remove: false });
|
case api.ui.ssmDel: return supportStart({ remove: true });
|
||||||
case api.ui.ssmDel: return func.sadd({ remove: true });
|
case api.ui.ssmClr: return supportClear();
|
||||||
case api.ui.ssmClr: return func.sclear();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// auto-detect supports
|
onEventFDM("key.esc", supportDone);
|
||||||
func.sgen = () => {
|
|
||||||
let alerts = [];
|
|
||||||
alerts.push(api.show.alert("analyzing part(s)...", 1000));
|
|
||||||
setTimeout(() => api.hide.alert(undefined,alerts), 2000);
|
|
||||||
}
|
|
||||||
|
|
||||||
// manual add supports
|
onEventFDM("slice.begin", supportDone);
|
||||||
func.sadd = ({ remove } = { remove: false }) => {
|
|
||||||
if (addingSupports) {
|
|
||||||
func.sdone();
|
|
||||||
if (removingSupports === remove) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
removingSupports = remove;
|
|
||||||
alert = api.show.alert(`[esc] key cancels ${remove?'removing':'adding'} supports`, 1000);
|
|
||||||
api.feature.hover = addingSupports = true;
|
|
||||||
api.feature.on_mouse_down = (int) => {
|
|
||||||
if (int) {
|
|
||||||
let { point } = int;
|
|
||||||
down = { point, widget: int.object.widget, z: int.face.normal.z };
|
|
||||||
}
|
|
||||||
return api.widgets.meshes();
|
|
||||||
};
|
|
||||||
api.feature.on_mouse_drag = ({ int }) => {
|
|
||||||
if (int?.length && int[0].face.normal.z < 0) {
|
|
||||||
func.sadd_point(int[0].point, down.widget, remove);
|
|
||||||
}
|
|
||||||
return [ down.widget.mesh ];
|
|
||||||
// return api.widgets.meshes();
|
|
||||||
};
|
|
||||||
api.widgets.each(w => {
|
|
||||||
let mat = w.cache.mat = w.mesh.material[0];
|
|
||||||
mat = w.mesh.material[0] = mat.clone();
|
|
||||||
mat.needsUpdate = true;
|
|
||||||
if (!w.anno.paint) {
|
|
||||||
w.anno.paint = [];
|
|
||||||
}
|
|
||||||
addPaintOverlayTexture(mat, w.anno.paint, new THREE.Color(0x4488ff));
|
|
||||||
})
|
|
||||||
api.space.update();
|
|
||||||
}
|
|
||||||
|
|
||||||
func.sadd_point = (point, widget, remove) => {
|
// onEventFDM("slice.end", api.noop);
|
||||||
let { x, y, z } = point;
|
|
||||||
let rec = {
|
|
||||||
point: { x, y:-z, z:y },
|
|
||||||
radius: 2
|
|
||||||
};
|
|
||||||
// return console.log({ on, widget, point });
|
|
||||||
let paint = widget.anno.paint;
|
|
||||||
let pt = newPoint(x, -z, y);
|
|
||||||
for (let r of paint) {
|
|
||||||
let { point } = r;
|
|
||||||
let dist = newPoint(point.x, point.y, point.z).distTo2D(pt);
|
|
||||||
if (remove && dist < 2) {
|
|
||||||
r.delete = true;
|
|
||||||
} else if (dist < 1) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (remove) {
|
|
||||||
paint = widget.anno.paint = paint.filter(rec => !rec.delete);
|
|
||||||
} else {
|
|
||||||
paint.push(rec);
|
|
||||||
}
|
|
||||||
updatePaintOverlay(widget.mesh.material[0], paint);
|
|
||||||
api.space.update();
|
|
||||||
api.conf.save();
|
|
||||||
};
|
|
||||||
|
|
||||||
// manual add done
|
onEventFDM("selection.scale", () => {
|
||||||
func.sdone = () => {
|
clearRanges();
|
||||||
if (!addingSupports) {
|
supportClear()
|
||||||
return;
|
|
||||||
}
|
|
||||||
api.feature.hover = addingSupports = false;
|
|
||||||
api.feature.on_mouse_down = undefined;
|
|
||||||
api.feature.on_mouse_drag = undefined;
|
|
||||||
api.hide.alert(alert);
|
|
||||||
api.widgets.each(w => {
|
|
||||||
w.mesh.material[0] = w.cache.mat;
|
|
||||||
delete w.cache.mat;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// manual supports clear
|
|
||||||
func.sclear = () => {
|
|
||||||
func.sdone();
|
|
||||||
api.widgets.each(w => clearWidgetSupports(w));
|
|
||||||
api.conf.save();
|
|
||||||
}
|
|
||||||
|
|
||||||
api.event.on("slice.begin", () => {
|
|
||||||
if (!isFdmMode) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
func.sdone();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
api.event.on("slice.end", () => {
|
// onEventFDM("widget.delete", api.noop);
|
||||||
if (!isFdmMode) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
api.event.on("key.esc", () => {
|
// onEventFDM("widget.duplicate", api.noop);
|
||||||
if (isFdmMode) {
|
|
||||||
func.sdone()
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
api.event.on("selection.scale", () => {
|
// onEventFDM("widget.mirror", api.noop);
|
||||||
if (isFdmMode) {
|
|
||||||
clearRanges();
|
|
||||||
func.sclear();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
api.event.on("widget.delete", widget => {
|
onEventFDM("widget.rotate", rot => {
|
||||||
if (isFdmMode) {
|
|
||||||
clearRanges();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
api.event.on("widget.duplicate", (widget, oldwidget) => {
|
|
||||||
if (!isFdmMode) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
api.event.on("widget.mirror", widget => {
|
|
||||||
if (!isFdmMode) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
api.event.on("widget.rotate", rot => {
|
|
||||||
if (!isFdmMode) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let {widget, x, y, z} = rot;
|
let {widget, x, y, z} = rot;
|
||||||
if (x || y) {
|
if (x || y) {
|
||||||
clearWidgetSupports(widget);
|
clearWidgetSupports(widget);
|
||||||
|
|
@ -323,20 +203,20 @@ export function init() {
|
||||||
api.conf.save();
|
api.conf.save();
|
||||||
});
|
});
|
||||||
|
|
||||||
api.event.on("mouse.hover.up", func.hoverup = (on = {}) => {
|
onEventFDM("mouse.hover.up", (on = {}) => {
|
||||||
if (!(addingSupports && isFdmMode)) {
|
if (!addingSupports) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let { object } = on;
|
let { object } = on;
|
||||||
if (object && down.z < 0) {
|
if (object && down.z < 0) {
|
||||||
let { point } = object;
|
let { point } = object;
|
||||||
let { widget } = object.object;
|
let { widget } = object.object;
|
||||||
func.sadd_point(point, widget, removingSupports);
|
supportUpdate(point, widget, removingSupports);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
api.event.on("mouse.hover", data => {
|
onEventFDM("mouse.hover", data => {
|
||||||
if (!(addingSupports && isFdmMode)) {
|
if (!addingSupports) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -364,4 +244,91 @@ function rotateWidgetPaint(widget, angle) {
|
||||||
point.x = x * cos - y * sin;
|
point.x = x * cos - y * sin;
|
||||||
point.y = x * sin + y * cos;
|
point.y = x * sin + y * cos;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// start manual add supports
|
||||||
|
function supportStart({ remove } = { remove: false }) {
|
||||||
|
if (addingSupports) {
|
||||||
|
supportDone();
|
||||||
|
if (removingSupports === remove) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
removingSupports = remove;
|
||||||
|
alert = api.show.alert(`[esc] key cancels ${remove?'removing':'adding'} supports`, 1000);
|
||||||
|
api.feature.hover = addingSupports = true;
|
||||||
|
api.feature.on_mouse_down = (int) => {
|
||||||
|
if (int) {
|
||||||
|
let { point } = int;
|
||||||
|
down = { point, widget: int.object.widget, z: int.face.normal.z };
|
||||||
|
}
|
||||||
|
return api.widgets.meshes();
|
||||||
|
};
|
||||||
|
api.feature.on_mouse_drag = ({ int }) => {
|
||||||
|
if (int?.length && int[0].face.normal.z < 0) {
|
||||||
|
supportUpdate(int[0].point, down.widget, remove);
|
||||||
|
}
|
||||||
|
return [ down.widget.mesh ];
|
||||||
|
// return api.widgets.meshes();
|
||||||
|
};
|
||||||
|
api.widgets.each(w => {
|
||||||
|
let mat = w.cache.mat = w.mesh.material[0];
|
||||||
|
mat = w.mesh.material[0] = mat.clone();
|
||||||
|
mat.needsUpdate = true;
|
||||||
|
if (!w.anno.paint) {
|
||||||
|
w.anno.paint = [];
|
||||||
|
}
|
||||||
|
addPaintOverlayTexture(mat, w.anno.paint, new THREE.Color(0x4488ff));
|
||||||
|
})
|
||||||
|
api.space.update();
|
||||||
|
}
|
||||||
|
|
||||||
|
function supportUpdate(point, widget, remove) {
|
||||||
|
let { x, y, z } = point;
|
||||||
|
let rec = {
|
||||||
|
point: { x, y:-z, z:y },
|
||||||
|
radius: 2
|
||||||
|
};
|
||||||
|
// return console.log({ on, widget, point });
|
||||||
|
let paint = widget.anno.paint;
|
||||||
|
let pt = newPoint(x, -z, y);
|
||||||
|
for (let r of paint) {
|
||||||
|
let { point } = r;
|
||||||
|
let dist = newPoint(point.x, point.y, point.z).distTo2D(pt);
|
||||||
|
if (remove && dist < 2) {
|
||||||
|
r.delete = true;
|
||||||
|
} else if (dist < 1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (remove) {
|
||||||
|
paint = widget.anno.paint = paint.filter(rec => !rec.delete);
|
||||||
|
} else {
|
||||||
|
paint.push(rec);
|
||||||
|
}
|
||||||
|
updatePaintOverlay(widget.mesh.material[0], paint);
|
||||||
|
api.space.update();
|
||||||
|
api.conf.save();
|
||||||
|
};
|
||||||
|
|
||||||
|
// manual add done
|
||||||
|
function supportDone() {
|
||||||
|
if (!addingSupports) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
api.feature.hover = addingSupports = false;
|
||||||
|
api.feature.on_mouse_down = undefined;
|
||||||
|
api.feature.on_mouse_drag = undefined;
|
||||||
|
api.hide.alert(alert);
|
||||||
|
api.widgets.each(w => {
|
||||||
|
w.mesh.material[0] = w.cache.mat;
|
||||||
|
delete w.cache.mat;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// manual supports clear
|
||||||
|
function supportClear() {
|
||||||
|
supportDone();
|
||||||
|
api.widgets.each(w => clearWidgetSupports(w));
|
||||||
|
api.conf.save();
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue