From f43ab7ec0e098190fa18e267e081019889ee27a5 Mon Sep 17 00:00:00 2001 From: Stewart Allen Date: Tue, 11 Oct 2022 13:52:08 -0400 Subject: [PATCH] substantially improve appearance of CAM animations by using solids instead of lines --- release.md | 2 +- src/kiri-mode/cam/animate.js | 75 ++++++++++++++++++++++++++---------- src/kiri/conf.js | 2 +- src/kiri/consts.js | 8 +++- src/kiri/stack.js | 6 +-- 5 files changed, 66 insertions(+), 27 deletions(-) diff --git a/release.md b/release.md index 1c51c25b..0fc91469 100644 --- a/release.md +++ b/release.md @@ -5,7 +5,7 @@ Full docs @ https://docs.grid.space/projects/kiri-moto # Release 3.6 -* improve CAM animation speeds +* improve CAM animation speeds and render quality using solids instead of lines * add CAM op level part offset parameters for xy and z * add CAM pocket smoothing and contouring which is closer to true 3 axis * add CAM 3D engraving and marking with the pocket contouring operation diff --git a/src/kiri-mode/cam/animate.js b/src/kiri-mode/cam/animate.js index 6ff71225..53716da8 100644 --- a/src/kiri-mode/cam/animate.js +++ b/src/kiri-mode/cam/animate.js @@ -8,6 +8,7 @@ gapp.register("kiri-mode.cam.animate", [], (root, exports) => { const { kiri } = root; const { driver } = kiri; const { CAM } = driver; +const asLines = false; let meshes = {}, unitScale = 1, @@ -42,6 +43,7 @@ kiri.load(() => { } function animate(api, delay) { + let alert = kiri.api.alerts.show("building animation"); kiri.client.animate_setup(api.conf.get(), data => { checkMeshCommands(data); if (!(data && data.mesh_add)) { @@ -70,6 +72,7 @@ kiri.load(() => { playButton.style.display = ''; pauseButton.style.display = 'none'; api.event.emit('animate', 'CAM'); + kiri.api.alerts.hide(alert); }); } @@ -98,12 +101,37 @@ kiri.load(() => { const geo = new THREE.BufferGeometry(); geo.setAttribute('position', new THREE.BufferAttribute(pos, 3)); geo.setIndex(new THREE.BufferAttribute(new Uint32Array(ind), 1)); - const mat = new THREE.LineBasicMaterial({ - transparent: true, - opacity: 0.75, - color - }); - const mesh = new THREE.LineSegments(geo, mat); + let mesh; + if (asLines) { + const mat = new THREE.LineBasicMaterial({ + transparent: true, + opacity: 0.75, + color + }); + mesh = new THREE.LineSegments(geo, mat); + } else { + let shininess = 120, + specular = 0x202020, + emissive = 0x101010, + metalness = 0.2, + roughness = 0.8, + flatShading = true, + transparent = true, + opacity = 0.9, + color = 0x888888, + side = THREE.DoubleSide; + if (!flatShading) { + geo.computeVertexNormals(); + } + const mat = new THREE.MeshMatcapMaterial({ + flatShading, + transparent, + opacity, + color, + side + }); + mesh = new THREE.Mesh(geo, mat); + } space.world.add(mesh); meshes[id] = mesh; } @@ -197,6 +225,7 @@ kiri.load(() => { if (data.mesh_add) { const { id, ind, pos, offset } = data.mesh_add; meshAdd(id, ind, pos); + space.refresh(); if (offset) { posOffset = offset; } @@ -303,26 +332,32 @@ kiri.load(() => { const ox = size.x / 2; const oy = size.y / 2; - const b = { mx: 0, my: 0, Mx: 0, My: 0}; - // initialize grid points for (let x=0, ai=0; x 0) ind.appendAll([ - (stepsY * x) + (y - 1), - (stepsY * x) + (y ) - ]); - if (x > 0) ind.appendAll([ - (stepsY * (x - 1)) + y, - (stepsY * (x )) + y - ]); - b.mx = Math.min(b.mx, px); - b.my = Math.min(b.my, py); - b.Mx = Math.max(b.Mx, px); - b.My = Math.max(b.My, py); + if (asLines) { + if (y > 0) ind.appendAll([ + (stepsY * x) + (y - 1), + (stepsY * x) + (y ) + ]); + if (x > 0) ind.appendAll([ + (stepsY * (x - 1)) + y, + (stepsY * (x )) + y + ]); + } else { + if (x > 0 && y > 0) { + let v0 = stepsY * (x - 1) + y - 1; + let v1 = stepsY * (x - 0) + y - 1; + let v2 = stepsY * (x - 0) + y; + let v3 = stepsY * (x - 1) + y; + ind.appendAll([ + v0, v1, v2, v0, v2, v3 + ]); + } + } } } diff --git a/src/kiri/conf.js b/src/kiri/conf.js index bd88b87b..d568b9df 100644 --- a/src/kiri/conf.js +++ b/src/kiri/conf.js @@ -716,7 +716,7 @@ const conf = exports({ exportPreview: false, decimate: true, detail: "50", - animesh: "300", + animesh: "800", healMesh: false, threaded: true, assembly: false, diff --git a/src/kiri/consts.js b/src/kiri/consts.js index 7a14340d..9ca5e68e 100644 --- a/src/kiri/consts.js +++ b/src/kiri/consts.js @@ -73,7 +73,13 @@ const LISTS = { { name: "600" }, { name: "700" }, { name: "800" }, - { name: "900" } + { name: "900" }, + { name: "1000" }, + { name: "1500" }, + { name: "2000" }, + { name: "2500" }, + { name: "3000" }, + { name: "4000" }, ], select: [ { name: "loops" }, diff --git a/src/kiri/stack.js b/src/kiri/stack.js index 7158dcfd..3cb28ccc 100644 --- a/src/kiri/stack.js +++ b/src/kiri/stack.js @@ -241,13 +241,11 @@ function createLineMaterial(color, array) { } function createStandardMaterial(color, flat) { - return new THREE.MeshStandardMaterial({ - emissive, - roughness, - metalness, + return new THREE.MeshMatcapMaterial({ transparent: color.opacity != 1, opacity: color.opacity || 1, color: color.face, + flatShading: true, side: flat ? THREE.DoubleSide : THREE.FrontSide }); }