GSOC 2021 Draft Proposal : Knife Tool Improvements

Not the final version of the GSOC proposal uploaded here. Few changes might be needed in the following draft, Feedbacks welcome till then.

Name

Pratik Pandurang Borhade

Contact

Synopsis

Several users have requested few features as well as proposed some improvements for existing tool options. Most of the code related to the Knife tool is under maintenance for a couple of years. Supplementing some user-requested features to the Knife tool makes it a good candidate for the GSOC project. Having fixed some bugs from the Modelling module, moderately familiar with the code.

Benefits

The project will add valuable features to the knife tool. The entire idea serves to make the Knife tool more powerful. Enhancements will make the tool more dynamic for artists. After the summer, artists can see the knife tool in a good position. Providing diversity in the tool will increase the strength of knife. Apart from tool improvement, I will be doing code clean-up.

Deliverable

  • Feature to add shape cuts (rectangle, circle, etc)
  • Undo feature
  • Improvements for snapping angle
  • Integrating measurements and providing scaling option for poly-line cut.
  • Multi-object editing (T56948).
  • User documentation, code cleanup.

(from artist’s and developer’s feedback so far, I noted some tasks which can be done during the program or after summer, one of them is to support pol-line cut for the object which has edges only)

Project Details

Most of the code I will work on during the summer belong to editmesh_knife.c.

Shape cuts for Simple Geometry

Usage of the Knife project is time-consuming for simple Geometry shapes. Providing shape functions (Eg. rectangle, circle) will make the job more straightforward. Howard Trickey and Campbell Barton suggest providing a tool option instead of hotkeys, which would be handier. The way existing code works, step-by-step poly-cut needs to be mapped to get an exact shape cut. After a complete cut, call the function BM_face_split_edgenet_connect_islands to join shape cut with boundary edges. Moreover, the function avoids the generation of loose edges.

Following enum name represents every shape.

enum{
KNF_SHAPE_POLY_LINE,
KNF_SHAPE_RECTANGLE,
KNF_SHAPE_CIRCLE,
}

Undo Feature

The feature will make it feasible to move one step back to the last vertex drawn. The stack data structure we can use here to hold all the drawn poly-edges in sequence. In my opinion, ListBase could be a good option in that case, since we can store the address of the first and last member of the list. We may not use operator ED_OT_undo for this feature so need to think for struct which can hold a list of all edges. Because the function
ed_undo_exec will reference to null data when cut is confirmed or cancel.

With this feature, the user can step back to the previous vertex with ctrl + z ( Note: user can not undo with edit-> undo because this UI option executes ed_undo_exec function )

Snapping Angle Improvements

Cian Jinks is working on UI for the snapping angle ( D10853 ) as of now. So the project will concentrate to implement orientation options. The intention is to provide additional snapping options (Global and Object-relative). The code belongs to knife_snap_angle function for the present snapping angle. Every orientation option requires different logic so will redesign the function.

A quite good vector calculation is expected for implementing snapping modes. With vector direction of Global X-axis and a knife vert, it is possible to draw a preview line parallel to Global X-axis(similar to other axes). With Geometry relative orientation enabled, an edge perpendicular to previous knife edge or boundary edge can be drawn.

Providing a dropdown as a tool option for mode switching.

Integrating Measurements

The task intends to measure the length of the current poly-edge cut. Besides, I have a plan to scale the poly-edge cut by number key input (identical to mesh resizing with number keys. Eg. Select default cube -> key S -> Number key 2, This will scale the cube to 2 units).
Referring to Vector math, With one fixed vertex with direction and length of a vector, a line is possible to draw in 3D. Relating to the example, in our case fixed vertex is the previous knife vertex, the direction is direction vector of the current knife position and the previous knife vertex where length is number key input.

Multi-object editing

Refer the task T56948 . It supports drawing poly edge cut for more than one object in edit mode. Supporting this feature will lead to important changes in the workflow of the knife tool.

For multi-object editing, KnifeTool_OpData will require a few changes to store the data of individual objects. I plan to add a new struct that will maintain the data (e.g. BMEditMesh, kverts, kedges) per object. So that every object can have its array of data. Where common properties like only_select, is_drag_hold, etc. can be kept in KnifeTool_OpData. This new structure will be a member variable of KnifeTool_OpData (Similar to TransInfo has a member variable of type TransDataContainer is used to store data of multiple objects).

Project Schedule

Semester exams will be around mid-June otherwise no plans to interfere with the GSOC project. Till the community bonding period, I can utilize my time. I will look into the present code of the Knife tool, will do triaging and bug fixes on the tracker till then. As College is appearing online for the entire semester so I can pull extra time to collect more ideas for the tool improvements.

  • Week 1: Adding tool options for shape cuts, working on a basic workflow for this feature
  • Week 2-3: Writing actual code for individual shape cuts
  • Week 3-4: Working on Undo feature.
  • Week 4-5: Improvements for Snapping Angle.
  • Week 6: Integrating measurement and scaling improvements for poly-line cut
  • Week 7-8-9: In this period I will work on Multi-object editing for the knife tool.
  • Week 10: User documentation, code cleanup.

Some tasks may take considerably more-less time than allotted but will complete the task in the same order. I am collecting more ideas from dev talk and RCS which I can take to work further after the program.

Bio

I am Pratik Pandurang Borhade, 2nd year engineering student at VIT, Mumbai (India). I have ample experience with C, C++. Noticed Blender software about a year ago when I was scrolling over the internet for 3D creation software. Using Blender to design meshes, animation, human rig, etc. Apart from Blender I did programming using Unity Game Engine, designed a few mobile applications using Android Studio.

I am contributing to Blender for the past 4-5 months. I do bug triaging in my spare time. As of now, I am a member of the Moderator’s group of Blender. Submitted a few patches. Some got accepted so far ( most from the Modeling module) :

D10824 (clean-up in editmesh_knife.c)

D10763 (fix for mesh size)

D10699 (fix for grid subdivision count)

D10497 (selection of non-manifold edge loop)

D10353 (fix for lattice resolution)

D10239 (Normalizing weight paint for gradient tool)

Also submitted a couple of patches (D10702 , D10785) but they have not made it to land. So far, it was a pleasant experience for me to help blender. Not major contribution did as of now but it’s satisfying to help countless artists through programming. I will continue my contribution and triaging after the program as well.

44 Likes

The most annoying thing in current Knife Tool, it’s if I make multiple cuts (clicks) and then click RMB, it cancel all my cuts from the very beginning…
In my opinion every click should make permanent cut and RMB click should undo last cut(click).

14 Likes

Perhaps an insignificant request. Knife tool does not work if there are no faces. It would be nice if Knife tool also works when there are only Edges, by creating new edges between edges.

10 Likes

For Undo, I had attempted it some time back but never completed it. Multiple levels of undo and redo should be possible and my code would more or less work in that situation. I would say your proposal should have multiple levels of undo and redo too.

However, attempting a completely new cut after undoing a few steps wasn’t implemented (rather critical :)). The C code there is not very friendly and at the time I didn’t know the appropriate blender structure to use to keep track of the KnifePosData items. Without this piece I couldn’t really fully test out my approach.

Another problem with the knife tool is how it tracks potential new knife edges and knife verts – if you debug the code you’ll find that it ends up allocating/adding dozens or hundreds of edges/verts if the user just travels along the edge of a face (get the green box to appear and just move your mouse, no clicking necessary). I tried to remove that aspect of things, which complicated my undo/redo code, but that concept seemed pretty ingrained in how it functions :-/

1 Like

A nice feature to support. It’s all about changing the entire workflow of knife tool. However, this can be implemented but it would not be possible to be done during the program ( the coding period is reduced this year ). Thanks for the Suggestion! :slight_smile:

1 Like

Nice suggestion! It can be the part of GSOC project. Will discuss with developers regarding this feature.Thanks!:slight_smile:

4 Likes

Hi @deadpin, thanks for the advice . Yes, looking forward to multiple level undo-redo for the project.

The Way knife tool works, it’s not possible to use ed_undo_exec, Some kind of structure needs to be used which will hold the steps. I thought ListBase would work in that case. If not, more investigation I will do.

Another problem with the knife tool is how it tracks potential new knife edges and knife verts …

I did not get it, could you please elaborate??

Thanks!:slight_smile:

This is a bit of an off topic tangent but I’ve always thought that blender’s approach to tools like this is a bit weird since it seems that it’s destructively making changes as you go, which maybe causes things like undo/redo to be more complicated than they need to be? Seems like it would be far more intuitive to store the input into a command list and render a ‘preview cut’ that looks like the real thing and is only executed when the operator is complete. then when you need to undo you’re basically just popping the last command from the list and refreshing the GL preview cut.

Honestly this one feels like a bit of scope creep for the knife tool. Maybe it would make more sense as a separate active tool-- just like we now have a separate tool for adding primitive meshes, there could be a separate tool for adding “primitive cuts”. I think that keeping the focus of the knife tool itself on the existing basic operation will make more sense in the long run.

The rest of the proposal seems like some great improvements though!

6 Likes

Hi @HooglyBoogly. Last week I discussed this feature on module channel, both Campbell and Howard Trickey thought the feature would be useful.

Thank you :slight_smile:

1 Like

I’m not saying it’s not useful, my point was that (IMO) it doesn’t exactly fit into what the knife tool does (draw a line, click to place the next point on the line, etc). Of course the final behavior is up to Campbell and Howard and other module members.

Actually, thinking a bit more generally, a feature being useful doesn’t necessarily mean that it conforms with design, is intuitive, and actually makes sense to add. I do see that conversation in the chat though. And I don’t mean to be negative, I’m glad to see you’re interested in working on all this!

3 Likes

I know what your concern was about. It can be a separate tool but for few shape cuts it might be good to keep in knife tool itself.
Thanks for reading and feedback (:

Set a debugger tracepoint or use printfs to see just how frequently new_knife_vert and new_knife_edge are called when moving the mouse over a mesh etc. Most of those newly created elements get ignored later using the is_cut field and some other logic.

I also tend to agree about the shape support. I’d probably vote on global/local axis snapping, undo/redo, and measurements (in that order) before the shapes.

1 Like

Will take a look soonish . I’ll get back to you on blender.chat

Guess I need to rethink about shape cut feature .

What about multi-objects cutting? It’s not something of a big deal just that would be nice to have since the other tools do work on multiple objects in edit mode.
Best of luck.

1 Like

Suggested task can be the part of GSOC project. I probably add one or two extra tasks which I could either finish during the program or after that.
Thanks :smiley:

I agree with the idea, although I think RMB is used as a cancel operator by multiple tools, so I think it’s coherent. There are vector apps that use backspace to dissolve last point/vertex while maintaining the rest of the line. Maybe a similar approach could be used here?

2 Likes

Pre-highlight on first use
Pre-highlight vertice before cut always

1 Like

What about Incremental magnet snapping on a edge with knife tool?
(by percentage steps or by number of points between vertices on a edge)
or is it already implemented?

This would be more helpful for basic modeling than a new shape cuts
Thanks.

I’m all in for Backspace to undo the very last operation while still being in the knife tool.

It’s not just vector apps who use this, it’s the same for “poligon lasso select” of most 2D applications.
With Backspace you don’t cancel the tool just undo the last click basically.
It’d fit the knife tool design very well.

PratikPB2125
Your GSoC project looks really good. I hope you’ll succeed and I’ll follow this topic closely!

4 Likes