From 3d59400c0b2adaae8190fc6852430fab80470f96 Mon Sep 17 00:00:00 2001 From: Stewart Allen Date: Thu, 19 Mar 2020 18:34:03 -0400 Subject: [PATCH] improved mouse down / move detection --- js/meta.js | 308 +++++++++++++++++++++++++++++++---------------- js/moto-space.js | 47 ++++---- 2 files changed, 232 insertions(+), 123 deletions(-) diff --git a/js/meta.js b/js/meta.js index 1b1b17bf..dba4e011 100644 --- a/js/meta.js +++ b/js/meta.js @@ -27,17 +27,22 @@ let gs_meta = exports; THREE.Material.prototype.motoSetup = function() { this.fog = false; + this.transparent = false; + let hidden = this.clone(); - this.m_hide = hidden; - this.m_show = this; + hidden.visible = false; + hidden.m_hide = hidden; hidden.m_show = this; - hidden.visible = false; + + this.m_hide = hidden; + this.m_show = this; + return this; }; THREE.Face3.prototype.mVisible = function(show) { - this.onface.cube.showHideFace(this.materialIndex, show); + this.onface.cube.showFace(this.materialIndex, show); }; (function() { @@ -136,7 +141,7 @@ THREE.Face3.prototype.mVisible = function(show) { }, // --------------- boxMaterial = new THREE.MeshPhongMaterial({ - side:THREE.DoubleSide, + side: THREE.DoubleSide, color: 0x00ff00, specular: 0x111111, transparent: false, @@ -236,12 +241,17 @@ THREE.Face3.prototype.mVisible = function(show) { matrix = {}, selected = [], // cubes selectable = [], // meshes - selectedBounds = new Bounds(); + selectedBounds = new Bounds(), + cubeID = 0; /** ****************************************************************** * LETS_GET_THIS_PARTY_STARTED() ******************************************************************* */ + function nextID() { + return ++cubeID; + } + function metaInit() { SPACE.showSkyGrid(false); SPACE.setSkyColor(0xf8f8f8); @@ -273,61 +283,62 @@ THREE.Face3.prototype.mVisible = function(show) { SPACE.mouse.downSelect(function(selection, event) { dragCopy = selection && event.metaKey; - return selectedFace ? [ selectedFace.cube.boxM ] : null; + // let mdr = selectedFace ? [ selectedFace.cube.boxy ] : null; + let mdr = selectedFace ? selectedFace.cube.boxy.children : null; + return mdr; }); SPACE.mouse.upSelect(function(selection, event) { - if (event) { - if (selection && selection.faceIndex) { - let face = selection.face.onface, - cube = face.cube; - switch (editMode) { - case EDIT.MARK: - if (!cube.isSynthetic()) markFace(face); - scheduleUpdateFaces(cube, face); - break; - case EDIT.SELECT: - let shift = event.shiftKey, - meta = event.metaKey, - isSelected = cube.isSelected(); - if (shift) { - selectRegion(face, true, meta ? SELECT.REGION : selectMode); - } else if (!isSelected) { - clearSelections(); - selectRegion(face, true, meta ? SELECT.REGION : selectMode); - } - if (cube.isSelected()) { - selectedFace = face; - scheduleUpdateFaces(cube, face); - } - let s = face.set, rot = { x: s.tx, y: s.ty, z: s.tz }; - SPACE.alignTracking(selection.point, rot, {x:-ABS(s.ox), y:-ABS(s.oz), z:-ABS(s.oy)}); - break; - case EDIT.ADD: - clearSelections(); - cube.newAdjacent(face).add(); - break; - case EDIT.CLONE: - clearSelections(); - cube.newAdjacent(face).add().cloneFrom(cube); - break; - case EDIT.DELETE: - if (cube.isSynthetic()) return; - clearSelections(); - removeCube(cube); - break; - } - } else { - clearSelections(); - } + if (!event) { + return selectable; + } + if (!(selection && selection.faceIndex >= 0)) { + return; + } + let face = selection.face.onface, + cube = face.cube; + switch (editMode) { + case EDIT.MARK: + if (!cube.isSynthetic()) markFace(face); + scheduleUpdateFaces(cube, face); + break; + case EDIT.SELECT: + let shift = event.shiftKey, + meta = event.metaKey, + isSelected = cube.isSelected(); + if (shift) { + selectRegion(face, true, meta ? SELECT.REGION : selectMode); + } else if (!isSelected) { + clearSelections(); + selectRegion(face, true, meta ? SELECT.REGION : selectMode); + } + if (cube.isSelected()) { + selectedFace = face; + scheduleUpdateFaces(cube, face); + } + let s = face.set, rot = { x: s.tx, y: s.ty, z: s.tz }; + SPACE.alignTracking(selection.point, rot, {x:-ABS(s.ox), y:-ABS(s.oz), z:-ABS(s.oy)}); + break; + case EDIT.ADD: + clearSelections(); + cube.newAdjacent(face).add(); + break; + case EDIT.CLONE: + clearSelections(); + cube.newAdjacent(face).add().cloneFrom(cube); + break; + case EDIT.DELETE: + if (cube.isSynthetic()) return; + clearSelections(); + removeCube(cube); + break; } - return selectable; }); SPACE.mouse.onDrag(function(delta, offset, end) { if (offset) moveSelection(offset); if (end) moveComplete(); - return selectedFace.cube.boxM; + return selectedFace.cube.boxy; }); SPACE.mouse.onHover(function(selection, event) { @@ -421,12 +432,11 @@ THREE.Face3.prototype.mVisible = function(show) { UC.newTableRow([ [ UC.newButton('x-', function() { rotateSelection(-1, 0, 0) }), - UC.newButton('x+', function() { rotateSelection( 1, 0, 0) }) - ],[ UC.newButton('y-', function() { rotateSelection( 0,-1, 0) }), - UC.newButton('y+', function() { rotateSelection( 0, 1, 0) }) + UC.newButton('z-', function() { rotateSelection( 0, 0,-1) }) ],[ - UC.newButton('z-', function() { rotateSelection( 0, 0,-1) }), + UC.newButton('x+', function() { rotateSelection( 1, 0, 0) }), + UC.newButton('y+', function() { rotateSelection( 0, 1, 0) }), UC.newButton('z+', function() { rotateSelection( 0, 0, 1) }) ] ]); @@ -434,12 +444,11 @@ THREE.Face3.prototype.mVisible = function(show) { UC.newTableRow([ [ UC.newButton('x-', function() { updateAnchorSelection(-1, 0, 0) }), - UC.newButton('x+', function() { updateAnchorSelection( 1, 0, 0) }) - ],[ UC.newButton('y-', function() { updateAnchorSelection( 0,-1, 0) }), - UC.newButton('y+', function() { updateAnchorSelection( 0, 1, 0) }) + UC.newButton('z-', function() { updateAnchorSelection( 0, 0,-1) }) ],[ - UC.newButton('z-', function() { updateAnchorSelection( 0, 0,-1) }), + UC.newButton('x+', function() { updateAnchorSelection( 1, 0, 0) }), + UC.newButton('y+', function() { updateAnchorSelection( 0, 1, 0) }), UC.newButton('z+', function() { updateAnchorSelection( 0, 0, 1) }) ],[ UC.newButton('center', function() { setAnchorSelection(0,0,0) }) @@ -455,6 +464,9 @@ THREE.Face3.prototype.mVisible = function(show) { ] ]); + UC.newGroup('options'); + UI.invert = UC.newBoolean('invert zoom', setZoom); + UC.newGroup('space', control); UI.name = UC.newInput('name', {size:10}); UI.units = UC.newInput('units'); @@ -521,6 +533,7 @@ THREE.Face3.prototype.mVisible = function(show) { /** and a few more settings before we're done */ setGridSize(gridSize); + setZoom(SDB['meta-zoom'] === 'true'); setSelectMode(SDB['meta-smode'] || SELECT.REGION,true); setMarkMode(SDB['meta-mmode'] || MARK.EMIT,true); setEditMode(EDIT.SELECT); @@ -533,6 +546,13 @@ THREE.Face3.prototype.mVisible = function(show) { ctrlRight.style.display = 'block'; } + function setZoom(value) { + if (value !== undefined) { + UI.invert.checked = value; + } + SPACE.view.setZoom(SDB['meta-zoom'] = UI.invert.checked); + } + function inputHasFocus() { return DOC.activeElement && (DOC.activeElement != DOC.body); } @@ -753,8 +773,6 @@ THREE.Face3.prototype.mVisible = function(show) { } setSelectMode(newSelect,true); setMarkMode(newMark,true); - // updateHighlights(selectModeButtons,editMode === EDIT.SELECT ? selectMode : null); - // updateHighlights(markTypeButtons,editMode === EDIT.MARK ? markMode : null); scheduleUpdateFaces(); hoverMaterial.color.setHex(color); SPACE.update(); @@ -905,28 +923,14 @@ THREE.Face3.prototype.mVisible = function(show) { }; function Cube(x, y, z, synth) { + this.id = nextID(); + this.pos = {x:x, y:y, z:z}; this.key = [x,y,z].join(','); this.synth = synth; this.selected = false; - this.materials = [ - boxMaterial, boxMaterial, boxMaterial, boxMaterial, boxMaterial, boxMaterial - ]; - - this.box = new THREE.BoxGeometry(1,1,1,1,1,1); - this.boxM = new THREE.Mesh(this.box, this.materials); - this.boxM.position.set(x, y, z); - this.boxM.cube = this; - - this.mesh = null; - this.meshRotate = null; - - this.group = new THREE.Object3D(); - this.group.cube = this; - this.group.add(this.boxM); - this.faces = { rl: this.makeFace('rl'), lr: this.makeFace('lr'), @@ -936,19 +940,109 @@ THREE.Face3.prototype.mVisible = function(show) { bt: this.makeFace('bt') }; - let b = this.box, f, key; - for (let i=0; i 0) { - let int = intersect(selection, selectRecurse); - if (int.length > 0) { - mouseUpSelect(int[0], event); - refresh = true; - } else { - mouseUpSelect(null, event); - } + let refresh = false, + selection = null; + if (mouseUpSelect) selection = mouseUpSelect(); + if (selection && selection.length > 0) { + let int = intersect(selection, selectRecurse); + if (int.length > 0) { + mouseUpSelect(int[0], event); + refresh = true; + } else { + mouseUpSelect(null, event); } - if (!refresh && platformClickAt) { - platformClick(platformClickAt); - } - if (refresh) requestRefresh(); } + if (!refresh && platformClickAt) { + platformClick(platformClickAt); + } + if (refresh) requestRefresh(); } else if (mouseDrag && mouseDragStart) { mouseDrag(null,null,true); } @@ -517,7 +523,6 @@ var MOTO = window.moto = window.moto || {}; requestRefresh(); } } - mouseMoved = true; mouse = { x: (event.clientX / width()) * 2 - 1, y: -(event.clientY / height()) * 2 + 1};