From 39656bb33a255a145f506b8eda5713734a43657d Mon Sep 17 00:00:00 2001 From: Stewart Allen Date: Thu, 19 Mar 2020 00:16:23 -0400 Subject: [PATCH] fix meshes to/from library --- js/add-three.js | 18 +++++++----------- js/meta.js | 24 ++++++++++++------------ web/meta/style.css | 6 +++--- 3 files changed, 22 insertions(+), 26 deletions(-) diff --git a/js/add-three.js b/js/add-three.js index f450ab1a..6049dfcb 100644 --- a/js/add-three.js +++ b/js/add-three.js @@ -77,17 +77,13 @@ // uniformly scale any mesh to a max x/y/z dim of 'unit' (defaults to 1) GP.unitScale = function(unit) { - var bbox = this.getBoundingBox(), - scale = unit || 1; - this.applyMatrix( - new THREE.Matrix3().identity().multiplyScalar(scale / - Math.max( - bbox.max.x - bbox.min.x, - bbox.max.y - bbox.min.y, - bbox.max.z - bbox.min.z - ) - ) - ); + var bbox = this.getBoundingBox().clone(), + scale = (unit || 1) / Math.max( + bbox.max.x - bbox.min.x, + bbox.max.y - bbox.min.y, + bbox.max.z - bbox.min.z + ); + this.applyMatrix4(new THREE.Matrix4().makeScale(scale,scale,scale)); // force update of (obsolete) bounding box this.getBoundingBox(true); return this; diff --git a/js/meta.js b/js/meta.js index 4292b07f..1b1b17bf 100644 --- a/js/meta.js +++ b/js/meta.js @@ -214,9 +214,9 @@ THREE.Face3.prototype.mVisible = function(show) { DATA = "/data/", // --------------- hashWatcher = null, - selectMode = SELECT.REGION, - editMode = EDIT.SELECT, - markMode = MARK.EMIT, + selectMode = null, + editMode = null, + markMode = null, updateFacesScheduled = false, updateSynthetic = true, enablePost = true, @@ -445,10 +445,10 @@ THREE.Face3.prototype.mVisible = function(show) { UC.newButton('center', function() { setAnchorSelection(0,0,0) }) ] ]); - UC.newGroup('send').setAttribute("title","send selection to target"); + UC.newGroup('export').setAttribute("title","send selection to target"); UC.newTableRow([ [ - UC.newButton('mesh', selectionToLibrary ), + UC.newButton('library', selectionToLibrary ), UC.newButton('kiri', selectionToKiri ) ],[ UC.newButton('download', downloadSelection ) @@ -476,7 +476,7 @@ THREE.Face3.prototype.mVisible = function(show) { UI.libdrop.id = "dropbutton"; UC.newRow([UI.libdrop]); - UC.newGroup('meshes'); + UC.newGroup('library'); UI.library = UC.newRow(); /** attach our key board controls */ @@ -521,9 +521,9 @@ THREE.Face3.prototype.mVisible = function(show) { /** and a few more settings before we're done */ setGridSize(gridSize); + setSelectMode(SDB['meta-smode'] || SELECT.REGION,true); + setMarkMode(SDB['meta-mmode'] || MARK.EMIT,true); setEditMode(EDIT.SELECT); - setMarkMode(SDB['meta-mmode'] || MARK.EMIT); - setSelectMode(SDB['meta-smode'] || SELECT.REGION); setSpaceUnits('1 cm'); restoreWorkspace(); @@ -764,16 +764,17 @@ THREE.Face3.prototype.mVisible = function(show) { updateHighlights(selectModeButtons,newmode); if (newmode == null) return; selectMode = parseInt(newmode); + SDB['meta-smode'] = selectMode; if (term) return; setEditMode(EDIT.SELECT,true); scheduleUpdateFaces(); - SDB['meta-smode'] = selectMode; } function setMarkMode(newmode,term) { updateHighlights(markTypeButtons,newmode); if (newmode === null) return; markMode = parseInt(newmode); + SDB['meta-mmode'] = markMode; selectedFace = null; if (term) return; setEditMode(EDIT.MARK,true); @@ -785,7 +786,6 @@ THREE.Face3.prototype.mVisible = function(show) { case MARK.CLEAR: color = COLOR.CLEAR; break; } hoverMaterial.color.setHex(color); - SDB['meta-mmode'] = markMode; SPACE.update(); } @@ -1024,7 +1024,7 @@ THREE.Face3.prototype.mVisible = function(show) { CP.rotateMesh = function(x,y,z,nostate) { if (this.mesh) { - this.mesh.geometry.applyMatrix(new THREE.Matrix4().makeRotationFromEuler( + this.mesh.geometry.applyMatrix4(new THREE.Matrix4().makeRotationFromEuler( new THREE.Euler((-x || 0) * PI2, (y || 0) * PI2, (-z || 0) * PI2)) ); @@ -1521,7 +1521,7 @@ THREE.Face3.prototype.mVisible = function(show) { if (LIBCACHE[filename]) callback(LIBCACHE[filename]); MDB.getFile(filename, function(vertices) { if (!vertices) return callback(); - let geo = THREE.Geometry.fromVertices(vertices).unitScale().center().fixNormals(); + let geo = THREE.Geometry.fromVertices(vertices.slice()).unitScale().center().fixNormals(); geo.filename = filename; callback(LIBCACHE[filename] = geo); }); diff --git a/web/meta/style.css b/web/meta/style.css index 8b784e1f..9bf0869c 100644 --- a/web/meta/style.css +++ b/web/meta/style.css @@ -18,10 +18,10 @@ .ck_spaces button { margin: 0px 0px 1px 2px !important; } -.ck_meshes { +.ck_library { padding-top: 2px; } -.ck_meshes div { +.ck_library div { -webkit-flex-direction: row; -webkit-justify-content: flex-start; -webkit-align-items: center; @@ -32,7 +32,7 @@ align-items: center; margin-bottom: 1px; } -.ck_meshes button { +.ck_library button { margin: 0px 0px 1px 2px !important; }