From 35448175ea2599f0c2850794f069dcdd5b41a7ac Mon Sep 17 00:00:00 2001 From: Stewart Allen Date: Tue, 10 Nov 2020 15:38:09 -0500 Subject: [PATCH] add build volume lines --- src/kiri/main.js | 6 +++-- src/moto/space.js | 64 +++++++++++++++++++++++++++++++++++++---------- 2 files changed, 55 insertions(+), 15 deletions(-) diff --git a/src/kiri/main.js b/src/kiri/main.js index af5c9d1b..ad578dc8 100644 --- a/src/kiri/main.js +++ b/src/kiri/main.js @@ -106,7 +106,8 @@ group: platformGroup, group_done: platformGroupDone, set_font: SPACE.platform.setFont, - set_axes: SPACE.platform.setAxes + set_axes: SPACE.platform.setAxes, + set_volume: SPACE.platform.setVolume }; const color = { @@ -966,7 +967,8 @@ SPACE.platform.setSize( width = parseInt(dev.bedWidth), depth = parseInt(dev.bedDepth), - height = parseFloat(dev.bedHeight) + height = parseFloat(dev.bedHeight), + parseFloat(dev.maxHeight) ); let proc = settings.process, ctrl = settings.controller, diff --git a/src/moto/space.js b/src/moto/space.js index ee80a2f1..5362294e 100644 --- a/src/moto/space.js +++ b/src/moto/space.js @@ -63,6 +63,7 @@ rulerColor, axisColor, axesOn = true, + volumeOn = true, viewControl, trackPlane, platform, @@ -71,6 +72,7 @@ platformClickAt, platformOnMove, platformMoveTimer, + volume, light1, light2, light3, @@ -215,7 +217,7 @@ requestRefresh(); } - function setPlatformSize(width, depth, height) { + function setPlatformSize(width, depth, height, maxz) { if (isRound) { platform.scale.set(width || 300, height || 5, depth || 175); } else { @@ -228,10 +230,38 @@ light2.position.set(-width, y, -depth); light4.position.set( width, light4.position.y, -depth); light5.position.set(-width, light5.position.y, depth); + if (volume) { + SCENE.remove(volume); + volume = null; + } + if (maxz) { + const points = [ + // pillars + {x: -width/2, z: -depth/2, y: 0}, + {x: -width/2, z: -depth/2, y: maxz}, + {x: width/2, z: depth/2, y: 0}, + {x: width/2, z: depth/2, y: maxz}, + {x: -width/2, z: depth/2, y: 0}, + {x: -width/2, z: depth/2, y: maxz}, + {x: width/2, z: -depth/2, y: 0}, + {x: width/2, z: -depth/2, y: maxz}, + // top + {x: -width/2, z: -depth/2, y: maxz}, + {x: -width/2, z: depth/2, y: maxz}, + {x: -width/2, z: -depth/2, y: maxz}, + {x: width/2, z: -depth/2, y: maxz}, + {x: width/2, z: depth/2, y: maxz}, + {x: width/2, z: -depth/2, y: maxz}, + {x: width/2, z: depth/2, y: maxz}, + {x: -width/2, z: depth/2, y: maxz}, + ]; + SCENE.add(volume = makeLinesFromPoints(points, 0x888888, 0.25)); + setVolume(volumeOn); + } } - function setPlatformSizeUpdateGrid(width, depth, height) { - setPlatformSize(width, depth, height); + function setPlatformSizeUpdateGrid(width, depth, height, maxz) { + setPlatformSize(width, depth, height, maxz); setGrid(gridUnitMajor, gridUnitMinor); } @@ -255,6 +285,12 @@ setRulers(); } + function setVolume(bool) { + volumeOn = bool; + if (volume) volume.visible = bool; + requestRefresh(); + } + function setRulers(drawX, drawY, offsetCenter) { if (drawX === undefined) drawX = rulerX; if (drawY === undefined) drawY = rulerY; @@ -552,22 +588,23 @@ * ThreeJS Helper Functions ******************************************************************* */ - function makeLinesFromPoints(points, color, width) { - if (points.length % 2 != 0) throw "invalid line : "+points.length; - let geo = new THREE.Geometry(), - i = 0, p1, p2, mesh; - while (i < points.length) { - p1 = points[i++]; - p2 = points[i++]; + function makeLinesFromPoints(points, color, opacity) { + if (points.length % 2 != 0) { + throw "invalid line : "+points.length; + } + const geo = new THREE.Geometry(); + for (let i=0; i < points.length; ) { + const p1 = points[i++]; + const p2 = points[i++]; geo.vertices.push(new THREE.Vector3(p1.x, p1.y, p1.z)); geo.vertices.push(new THREE.Vector3(p2.x, p2.y, p2.z)); } geo.verticesNeedUpdate = true; - mesh = new THREE.LineSegments(geo, new THREE.LineBasicMaterial({ + return new THREE.LineSegments(geo, new THREE.LineBasicMaterial({ color: color, - linewidth: width || 1 + opacity: opacity || 1, + transparent: opacity != 1 })); - return mesh; } function intersect(objects, recurse) { @@ -752,6 +789,7 @@ setGrid: setGrid, setFont: setFont, setAxes: setAxes, + setVolume: setVolume, add: function(o) { WORLD.add(o) }, remove: function(o) { WORLD.remove(o) }, setMaxZ: function(z) { panY = z / 2 },