-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Eraser #6994
Eraser #6994
Conversation
|
This reverts commit 302a23b.
This reverts commit cce4ac1.
handle transform in dedicated clip path group instead of in canvas
Only erasable objects will be visibly affected by the eraser brush. * In order to support selective erasing all non erasable objects are rendered on the main ctx * while the entire canvas is rendered on the top ctx. * When erasing occurs, the path clips the top ctx and reveals the main ctx. * This achieves the desired effect of seeming to erase only erasable objects.
This reverts commit 10bbfae.
I see the tests fail because of |
Let me see if with build:fast fixed it pass. |
Ok there are just some minor lint issues. can you run |
lint passed 0f81013 |
Would be cool if we can work on a demo for the main website |
Hi ! Do you know when this feature will be published to the NPM package ? |
Next release is in automatically. Soon since we also merged RTL text |
@asturur Could you point me to the exact place where I can add a demo in the website repo? |
This is an example of the demo. To load the website locally: |
Is there any user documentation for this? |
It is excluded from the default build so you need to create a custom build |
I would like to use this feature while using the npm module for simplicity. Add and execute below:
|
As would I. |
Thank you! |
@matsu-motsu Great, look at the fix #7100 |
You can use it from the npm module anyway, you can add a post-install script in your installation that will rebuild fabric adding the module. |
Thanks latest fix got rid of erased area returning after mouseup issue. |
@ShaMan123 There is an issue in my environment where I am using IText and when using this eraser function, the last IText object disappears while mouse is down but returns on mouseup. |
@ShaMan123 Ok, thanks for checking, if I can replicate the problem in the sandbox I'll let you know. |
I'm currently using this feature and it seems great! One issue though is that even after completely deleting all a drawing, the drawing remains selectable as an invisible group. Is there any way to clear the "erased" drawings? I need to export the JSON and I'm worried it becomes infinitely large. |
How can I remove erased objects in canvas, only when I have fully erased the object? |
This PR adds an ERASER brush.
You can test it in codesandbox.
UPDATE: The eraser has moved https://github.com/ShaMan123/erase2d
Inspiration
#1225 (comment)
Object Logic
clipPath
attr andEraserPath
to achieve erasing effectBrush Rendering Logic
EraserBrush
extendsPencilBrush
.Use top context to achieve an erasing effect while drawing - draw canvas on top context and leave only non erasable objects on main context. This way when the user erases the top context is drawn out and the main context with non erasables is revealed. 🚀💪👍👍
renderBottomLayer
renderTopLayer
fabric.PencilBrush#_render
atrenderTopLayer
renderOverlay
The canvas is prepared for every step/layer according to appropriate logic, hiding unnecessary objects and restoring them after painting.
Layer 1 is drawn on main/bottom ctx, the rest on top ctx.
Layers 2, 3 are affected by the brush.
Usage
added
erasable
option toObject
controlling whether it can be erased by the brush.EraserBrush is the same as PencilBrush in terms of use.
Caveats
1. Currently usingFixed 6d9c7ffabsolutePositioned
for clipPath - this causes a problem when selecting and moving an erased object. The eraser paths don't move with the object. I'm pretty sure there's some kind of transform function available to render the clipPath relatively. Would be glad to know which.2.DONE 127de4bonMouseMove
is a challange - I have changed the drawing context (fromcanvas.contextTop
tocanvas.getContext()
) so that the brush behaves as a clip path for the entire canvas. Not desirable though, in case of objects which are not erasable. I've seen that animated objects are drawn on a different canvas as well so that needs to be addressed.3.
I haven't addressed export/import of eraser data as part of the clip pathNeed to handleexport to svg now supported 1257489 47e6873, REMAININGtoSVG
fromSVG
4.
Using animation when erasing needs handlingDONEPerformance
Superb!
Motivation is obvious
#1225 #5742 #6356 #6261 #5595 #5273 #5188 #6964