Fabric Eraser w/ Eraser2d #10865
Replies: 2 comments 1 reply
-
|
Your explanation and code really cleared things up for me. I was stuck on this for a while, and your solution saved a lot of time. I forgot ask about the PR you made for editable tables features. happy coding.. |
Beta Was this translation helpful? Give feedback.
-
|
Hi @mauricekindermann, I'm building a canvas editor using Fabric.js v6.9.1 and I've implemented a custom layer system using a layer property on each object (e.g. background: 0, image: 1, shape: 2, text: 3). I sort canvas._objects directly based on this property whenever a new object is added. Is directly mutating canvas._objects for sorting considered safe in v6, or is there a proper API for this? Happy to share the full code if helpful. Thanks! export function applyZIndex(obj, direction, canvas) { const objects = canvas._objects; switch (direction) { export const LAYER_ORDER = { export const sortLayers = (canvas) => { const objects = canvas.getObjects(); const getLayerValue = (obj) => { const activeObject = canvas.getActiveObject(); // In Fabric v6, _objects is the internal array — sort it directly // Restore active object canvas.requestRenderAll(); |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
@shivasubramaniyam asked a quesiton on #8310
@erase2d/fabric) works great - it clips objects individually instead of nuking the whole canvas bitmap - but its live preview composites three canvases together which creates a white halo while you draw_renderon the brush instance to skip that compositing and just draw a normal brush trail instead_setBrushStylesto make that trail semi-transparent white so you can see where you're erasing without it being obnoxiouscommit()runs untouched - that's where the real clipPath erasing happens, per-object, no halobackgroundColorOf course you could set the brush to be the same color as the canvas i fyou like, but Ithink the UX is better having a before/after.
Here's the code:
https://codepen.io/goldencarers/pen/vEKreKG
Beta Was this translation helpful? Give feedback.
All reactions