From ec72a0097d8d29ec4adb0fc485ad572405fef17c Mon Sep 17 00:00:00 2001 From: casperlamboo Date: Thu, 14 Dec 2017 11:16:27 +0100 Subject: [PATCH] clean up --- src/components/D3Panel.js | 2 +- src/components/SketcherToolbars.js | 25 +++++++++++++------------ src/components/SubMenu.js | 5 +++-- src/constants/menu.js | 2 +- src/d3/MatcapMaterial.js | 9 +++++---- src/d3/OutlinePass.js | 12 ++++++------ src/utils/async.js | 4 ++-- src/utils/dbUtils.js | 2 +- src/utils/exportUtils.js | 10 +++++++--- src/utils/reactUtils.js | 2 +- src/utils/selectionUtils.js | 6 +++--- src/utils/threeUtils.js | 2 +- workers/trace.worker.js | 4 +--- 13 files changed, 45 insertions(+), 40 deletions(-) diff --git a/src/components/D3Panel.js b/src/components/D3Panel.js index 0070aec..52f18fc 100644 --- a/src/components/D3Panel.js +++ b/src/components/D3Panel.js @@ -62,7 +62,7 @@ class D3Panel extends React.Component { componentWillMount() { this.createScene(); - const toonShader = hasExtensionsFor.toonShaderPreview + const toonShader = hasExtensionsFor.toonShaderPreview; this.renderChain = new RenderChain(this.renderer, this.scene, this.camera, toonShader, { UI: this.UIContainer, shapes: this.shapesManager, diff --git a/src/components/SketcherToolbars.js b/src/components/SketcherToolbars.js index cbd4217..708bb80 100644 --- a/src/components/SketcherToolbars.js +++ b/src/components/SketcherToolbars.js @@ -20,20 +20,20 @@ const CONTEXT = 'context'; const styles = { contextMenuContainer: { - position: 'absolute', - left: 0, - bottom: 0, - right: 0, - top: 0, - display: 'flex', - justifyContent: 'center', - alignItems: 'center', - pointerEvents: 'none', /* enable clicking through object */ + position: 'absolute', + left: 0, + bottom: 0, + right: 0, + top: 0, + display: 'flex', + justifyContent: 'center', + alignItems: 'center', + pointerEvents: 'none', /* enable clicking through object */ '& *': { - pointerEvents: 'visible' /* enable clicking in children */ + pointerEvents: 'visible' /* enable clicking in children */ } } -} +}; class SketcherToolbars extends React.Component { @@ -41,7 +41,8 @@ class SketcherToolbars extends React.Component { dispatch: PropTypes.func.isRequired, toolbar2d: PropTypes.object, // TODO: specify further toolbar3d: PropTypes.object, // TODO: specify further - context: PropTypes.object // TODO: specify further + context: PropTypes.object, // TODO: specify further + classes: PropTypes.objectOf(PropTypes.string) }; onSelect2D = ({ value }) => { const { dispatch } = this.props; diff --git a/src/components/SubMenu.js b/src/components/SubMenu.js index 44f4ea8..8c8dceb 100644 --- a/src/components/SubMenu.js +++ b/src/components/SubMenu.js @@ -2,7 +2,6 @@ import React from 'react'; import PropTypes from 'prop-types'; import Button from './Button.js'; import Menu from './Menu.js'; -import bowser from 'bowser'; import { connect } from 'react-redux'; import { hexToStyle } from '../utils/colorUtils.js'; // import createDebug from 'debug'; @@ -21,7 +20,9 @@ class SubMenu extends React.Component { svg: PropTypes.string, children: PropTypes.node, selectOnOpen: PropTypes.bool, - toggleBehavior: PropTypes.bool + toggleBehavior: PropTypes.bool, + color: PropTypes.number, + solid: PropTypes.bool }; componentWillMount = () => { // Listeners to close the submenu when anywhere else is clicked diff --git a/src/constants/menu.js b/src/constants/menu.js index 73bff2b..680bb66 100644 --- a/src/constants/menu.js +++ b/src/constants/menu.js @@ -46,7 +46,7 @@ const toolbar3d = { children: [ { value: d3Tools.HEIGHT }, { value: d3Tools.SCULPT }, - { value: d3Tools.TWIST }, + { value: d3Tools.TWIST } // { value: d3Tools.STAMP } ] }; diff --git a/src/d3/MatcapMaterial.js b/src/d3/MatcapMaterial.js index 3f0eb54..06417b0 100644 --- a/src/d3/MatcapMaterial.js +++ b/src/d3/MatcapMaterial.js @@ -12,9 +12,9 @@ export default class MatcapMaterial extends THREE.ShaderMaterial { constructor({ color = new THREE.Color(), opacity = 1 }) { super({ uniforms: { - "opacity": { type: 'f', value: opacity }, - "tMatcap": { type: 't', value: matcapTexture }, - "color": { type: 'vec3', value: new THREE.Vector3() } + opacity: { type: 'f', value: opacity }, + tMatcap: { type: 't', value: matcapTexture }, + color: { type: 'vec3', value: new THREE.Vector3() } }, vertexShader: matcapVert, fragmentShader: matcapFrag @@ -35,7 +35,8 @@ export default class MatcapMaterial extends THREE.ShaderMaterial { set opacity(opacity) { if (!this.uniforms) return opacity; - return this.uniforms.opacity.value = opacity; + this.uniforms.opacity.value = opacity; + return opacity; } clone() { diff --git a/src/d3/OutlinePass.js b/src/d3/OutlinePass.js index 8ea18ef..606021f 100644 --- a/src/d3/OutlinePass.js +++ b/src/d3/OutlinePass.js @@ -26,8 +26,8 @@ export default class OutlinePass { this._edgeMaterial = new THREE.ShaderMaterial({ uniforms: { - "tDiffuse": { type: 't', value: this._depthNormalRenderTarget.texture }, - "resolution": { type: 'v2', value: new THREE.Vector2() } + tDiffuse: { type: 't', value: this._depthNormalRenderTarget.texture }, + resolution: { type: 'v2', value: new THREE.Vector2() } }, vertexShader: edgeVert, fragmentShader: edgeFrag @@ -35,12 +35,12 @@ export default class OutlinePass { this._copyEdge = new THREE.ShaderMaterial({ uniforms: { - "tDiffuse": { type: 't', value: null }, - "uTexArray" : { type: 'tv', value: [this._edgeRenderTarget.texture] } + tDiffuse: { type: 't', value: null }, + uTexArray : { type: 'tv', value: [this._edgeRenderTarget.texture] } }, vertexShader: combineVert, fragmentShader: combineFrag - }) + }); this._camera = new THREE.OrthographicCamera(-1, 1, 1, -1, 0, 1); this._scene = new THREE.Scene(); @@ -55,7 +55,7 @@ export default class OutlinePass { this._edgeMaterial.uniforms.resolution.value.set(width, height); } - render(renderer, writeBuffer, readBuffer, delta, maskActive) { + render(renderer, writeBuffer, readBuffer) { if (this._callbackBeforeRender) this._callbackBeforeRender(); this._copyEdge.uniforms.tDiffuse.value = readBuffer.texture; diff --git a/src/utils/async.js b/src/utils/async.js index 705923b..c260378 100644 --- a/src/utils/async.js +++ b/src/utils/async.js @@ -52,13 +52,13 @@ export function createThrottle() { if (!startLoop) return null; - return function loop() { + return (function loop() { const promise = next().then(() => { if (typeof next === 'function') return loop(); }); next = true; return promise; - }().then(() => { + })().then(() => { next = null; }); }; diff --git a/src/utils/dbUtils.js b/src/utils/dbUtils.js index 54e2b9a..aba80cf 100644 --- a/src/utils/dbUtils.js +++ b/src/utils/dbUtils.js @@ -20,7 +20,7 @@ export function getDbUrl(db) { } else { return `${db.protocol}${db.host}`; } -}; +} const dbs = {}; export function getDb(dbUrl) { diff --git a/src/utils/exportUtils.js b/src/utils/exportUtils.js index 1d553bb..93ac33c 100644 --- a/src/utils/exportUtils.js +++ b/src/utils/exportUtils.js @@ -79,7 +79,10 @@ export function generateExportMesh(state, options = {}) { }; for (const id in state.objectsById) { - exportState.objectsById[id] = createExportShapeData(state.objectsById[id], offsetSingleWalls || unionGeometry, lineWidth); + const shapeData = state.objectsById[id]; + if (!SHAPE_TYPE_PROPERTIES[shapeData.type].D3Visible) continue; + const exportShapeData = createExportShapeData(shapeData, offsetSingleWalls || unionGeometry, lineWidth); + exportState.objectsById[id] = exportShapeData; } const shapesManager = new ShapesManager({ toonShader: false }); @@ -91,10 +94,11 @@ export function generateExportMesh(state, options = {}) { const shapeData = exportState.objectsById[mesh.name]; if (mesh instanceof THREE.Mesh && shapeData.solid) { const { geometry, material } = mesh; + const objectMatrix = state.spaces[shapeData.space].matrix; let objectGeometry = geometry.clone(); objectGeometry.mergeVertices(); - objectGeometry.applyMatrix(new THREE.Matrix4().multiplyMatrices(state.spaces[shapeData.space].matrix, matrix)); + objectGeometry.applyMatrix(new THREE.Matrix4().multiplyMatrices(objectMatrix, matrix)); const colorHex = material.color.getHex(); let materialIndex = materials.findIndex(exportMaterial => exportMaterial.color.getHex() === colorHex); @@ -149,7 +153,7 @@ export async function createFile(state, type, options) { } case 'stl-blob': { const buffer = exportSTL.fromMesh(exportMesh, true); - return new Blob([buffer], { type: 'application/vnd.ms-pki.stl' }) + return new Blob([buffer], { type: 'application/vnd.ms-pki.stl' }); } case 'obj-blob': { const buffer = await exportOBJ.fromMesh(exportMesh); diff --git a/src/utils/reactUtils.js b/src/utils/reactUtils.js index fbd4203..13aeb7f 100644 --- a/src/utils/reactUtils.js +++ b/src/utils/reactUtils.js @@ -45,5 +45,5 @@ export function asyncValidateForm(dispatch, form, asyncValidate, formData) { dispatch(stopAsyncValidation(form)); }).catch(error => { dispatch(stopAsyncValidation(form, error)); - }) + }); } diff --git a/src/utils/selectionUtils.js b/src/utils/selectionUtils.js index 48a941f..7ad47fc 100644 --- a/src/utils/selectionUtils.js +++ b/src/utils/selectionUtils.js @@ -1,13 +1,13 @@ import * as THREE from 'three'; -import { shapeToPoints } from '../shape/shapeToPoints.js' -import { getPointsBounds } from '../shape/shapeDataUtils.js' +import { shapeToPoints } from '../shape/shapeToPoints.js'; +import { getPointsBounds } from '../shape/shapeDataUtils.js'; import { Vector } from 'cal'; import arrayMemoizer from './arrayMemoizer.js'; import memoize from 'memoizee'; // import createDebug from 'debug'; // const debug = createDebug('d3d:util:selection'); -// Memoized selector that returns the same array of shapeSata's when +// Memoized selector that returns the same array of shapeData's when // - the selection array didn't change // - the objects in the resulting array didn't change // enables memoization of utils that use this array diff --git a/src/utils/threeUtils.js b/src/utils/threeUtils.js index 1fff057..d828dd4 100644 --- a/src/utils/threeUtils.js +++ b/src/utils/threeUtils.js @@ -1,5 +1,5 @@ import * as THREE from 'three'; -import { loadImage } from './imageUtils.js' +import { loadImage } from './imageUtils.js'; import createDebug from 'debug'; const debug = createDebug('d3d:threeUtils'); diff --git a/workers/trace.worker.js b/workers/trace.worker.js index a57ed66..be1351b 100644 --- a/workers/trace.worker.js +++ b/workers/trace.worker.js @@ -74,9 +74,7 @@ function floodFill(imageData, start, tolerance) { for (let i = 0; i < neighbours.length; i ++) { const neighbourIndex = neighbours[i]; - if (!done[neighbourIndex]) { - stack.push(neighbourIndex); - } + if (!done[neighbourIndex]) stack.push(neighbourIndex); done[neighbourIndex] = true; } }