diff --git a/src/d2/Shape.js b/src/d2/Shape.js index 6fdc9e3..3995fc4 100644 --- a/src/d2/Shape.js +++ b/src/d2/Shape.js @@ -57,6 +57,10 @@ export default class Shape extends Matrix { changed = true; } + if (!this._shapeData || this._shapeData.solid !== shapeData.solid) { + changed = true; + } + this._shapeData = shapeData; return changed; } diff --git a/src/d2/ShapesManager.js b/src/d2/ShapesManager.js index aa11658..b022184 100644 --- a/src/d2/ShapesManager.js +++ b/src/d2/ShapesManager.js @@ -1,4 +1,4 @@ -import { shapeDataToShape, determineActiveShape } from '../shape/shapeDataUtils.js'; +import { shapeDataToShape, determineActiveShape2d } from '../shape/shapeDataUtils.js'; // import R from 'ramda'; export default class ShapesManager { @@ -15,7 +15,7 @@ export default class ShapesManager { const needRender = { active: false, inactive: false }; // determine if shape is "active", meaning it will be updated frequently - const activeShapes = determineActiveShape(state); + const activeShapes = determineActiveShape2d(state); const { objectsById } = state; diff --git a/src/shape/shapeDataUtils.js b/src/shape/shapeDataUtils.js index 1c1cd32..a2032cd 100644 --- a/src/shape/shapeDataUtils.js +++ b/src/shape/shapeDataUtils.js @@ -70,27 +70,11 @@ function shapeDataToShapeRaw(shapeData) { } } -// TODO can maybe be memoized -export const determineActiveShape = (state) => { - const activeTransformer = state.d2.eraser.active || - state.d2.transform.active || - state.d3.height.active || - state.d3.sculpt.activeHandle !== null || - state.d3.twist.active; - +export const determineActiveShape2d = (state) => { const selectedObjects = state.selection.objects.map(({ id }) => id); - const activeShapes = {}; - for (const id in state.objectsById) { - if (state.d2.activeShape === id) { - activeShapes[id] = true; - continue; - } - if (activeTransformer && !state.objectsById[id].solid) { - activeShapes[id] = true; - continue; - } - activeShapes[id] = selectedObjects.includes(id) && activeTransformer; - } + const activeShapes = Object.keys(state.objectsById) + .filter(id => state.d2.activeShape === id || selectedObjects.indexOf(id) !== -1); + return activeShapes; };