slic3r / Slic3r

Open Source toolpath generator for 3D printers
https://slic3r.org/
GNU Affero General Public License v3.0
3.33k stars 1.29k forks source link

GSoC 2018 - Rotating Face to Bottom #4397

Closed lordofhyphens closed 4 years ago

lordofhyphens commented 6 years ago

This issue is for @TheThirdOne to maintain his development log for his Slic3r GSoC 2018 project.

User story:


As a user, I want to be able to rotate models so that a given face lay flat against the build plate, so that I can manage plating difficult 3D models in Slic3r and not have to work out the rotation and translation math by hand.


This user story describes a wish described in #3047.


Open Design Questions:

If, after rotating and moving the model to put some face X onto the bed, another part of the model would be placed below the bed, what should be done?

VanessaE commented 6 years ago

Imho, if the attempted rotation puts part of the model below the plate, don't rotate, but do throw an error.

lordofhyphens commented 6 years ago

My own thoughts on whether to push the model up or error is to push the model up in Z.

dwillmore commented 6 years ago

What is the purpose or this rotation/translation? 1) help orient the model so that it's more readily printable with the given technology 2) designate the 'bottom' of the model

For 1, then it makes sense to auto-add some kind of support/raft to the model or at least display a warning saying that the given facet is not a valid 'bottom'

For 2, orient it as comanded and let the part below the bottom hang. Maybe throw an error, but orient the model as instructed. It wouldn't hurt to display how much the model extends below the bed in case the user wants to make an educated decision as to what to do with the sub-bed portion. It might be a rounding error that throws this error and the use would be wise to ignore it. Or it might have escaped their notice and they need to deal with it some other way.

I don't like 1, but I think 2 doesn't do enough. Maybe the error dialog could be ask "leave it alone and let Xmm hang below the bed", "auto-raise it up and add support/raft", "cancel".

foreachthing commented 6 years ago

If I choose a certain face to be down, then for a reason. So, please, don't bother me with errors. Adjust the model in Z accordingly -> auto-rise, like @dwillmore said.

MoonshineSG commented 6 years ago

agree with @foreachthing. If the user select a face, it does so for a reason. A non-intrusive note/alert can be displayed to indicate that part of the model is below the bed. Highlight the "below the bed" in a different color to make it easily identifiable.

gege2b commented 6 years ago

I think we should just place the part oriented so the selected face is on the plater, and then, if needed, rise the whole model up

user will enable support if needed

warnings could be displayed in a non annoying way (i.e. : " :warning: model was raised up automatically" in the status bar)

gege2b commented 6 years ago

another possibility is to give user two menu entries (or whatever else the feature would be triggered)

pro: everyone should be happy, no confirmation, no question, no warnings con: two menu entries instead of one

qknight commented 6 years ago

https://github.com/prusa3d/Slic3r/issues/147#issuecomment-389184624

lordofhyphens commented 6 years ago

@TheThirdOne need an update here as to what you did yesterday ;)

TheThirdOne commented 6 years ago

To summarize and to put my thoughts on the discussion about how underhang should be handled, it seems like most people are in favor of not erroring out, but at most giving a warning. There is not consensus about if the model should be moved up, kept where it is, or use two separate actions to do both.

My main concern with allowing part of the model to stay below the bed is that I don't believe any part of Slic3r can currently move things below the bed so that might be an assumption of various parts of the code. As a result, it might be a source of bugs; I may have missed a feature which allows you to position below the bed though. One option to combat that is to clip off the underhang, but that would likely be a fiar amount more work to implement.

Yesterday I was able to get the start to a selection system working. It currently has two issues: it doesn't highlight the entire connected face just a triangle and its a bit slower than I would like. Here's a gif of it working.

output

lordofhyphens commented 6 years ago

Rather than highlighting the face, what about drawing a new face/plane?

TheThirdOne commented 6 years ago

I like the idea of using a plane to note what face is going to be rotated. I think I would prefer highlighting the face all else being equal, but I hadn't considered drawing a new plane.

lordofhyphens commented 6 years ago

Yeah, all you really care about is what plane gets used, so a slightly-offset plane parallel to the face would probably get the job done and would be easier to read, I think.

TheThirdOne commented 6 years ago

One of the first things I did was fix the speed of the face select. There isn't any noticeable lag on it anymore. I also setup selection for faces in addition to hover.

fasterselect

After that I set up some UI for testing, trying to get to the rotation part. And then struggled understanding the code around where I would be doing the rotation. I think I should be good for tomorrow now though because of my chat(s) with @lordofhyphens in the IRC.

MoonshineSG commented 6 years ago

@TheThirdOne if it helps to know, other slicers that have this function have single triangle instead of full face highlight. There's no "selection". When you click on the triangle it imediatly rotates the object.

And if the chosen face is not necesarily the one that is touching the bed, but it's the one facing the bed. Basically the user selects "down" and the models get's place on the bed with the "down" parallel to the bed at the lowest posible Z, but not under the bed. (hopefully this makes sense)

qknight commented 6 years ago

@TheThirdOne as @MoonshineSG also sais, we probably don't need a "permanent selection" indicator, the "mouse over selection" is sufficient! i'd also recommend to stay with the "triangle hoover" as it makes programming easier and for most parts i assume it will just work as most often the problem is that a 'cut' surface, which wasn't aligned down needs to be rotated down and therefore there the triangle surfaces will be quite big.

regarding the problem with the selected triangle not being the lowest one and making parts of the model overlap the zero plane you might have to come up with something you can actually implement. and later we'll see if that works in practice. i didn't even find an example STL to play with, anyone else?

maybe we should put together a list of thingiverse parts which act as an "example problem" so you can test the usability of your implementation.

you work looks great so far!

MoonshineSG commented 6 years ago

@qknight @TheThirdOne : I'm always of the opinion that having something that "just works" and later improve it is better than not having anything but "we are working on the best ever solution". Do someting, put it out there for people to try and give feedback and mostly remember... you can never please everyone!

qknight commented 6 years ago

@lordofhyphens

My own thoughts on whether to push the model up or error is to push the model up in Z. The model is still oriented accordingly and support normally will be generated. That the model isn't flush against the selected face is already an indicator to the user that what they want is impossible. Undo/Redo is available, so "mistakes" are recoverable in these situations.

this is a brilliant idea as this technique can then also be used to align certain surfaces to the ground plate for cutting

lordofhyphens commented 6 years ago

Minor thing to remember for later: There's color schemes in Slic3r and so the highlight color should be set up according to that system.

TheThirdOne commented 6 years ago

I am aware. Pure red and blue were just easy to hardcode to help me work through it. I do plan on taking a second pass to fix things like the color scheme and decide how the UI should behave.

TheThirdOne commented 6 years ago

I didn't make much visible progress today, but I am made progress getting the face normal and have begun work moving that value to the code to rotate (which is not complete).

mariusstrom commented 6 years ago

FYI when you do this in Simplify3D (select a face to go on the plate that wouldn't be the lowest part of the model), S3D does what some described above: sets the face on the plate, then silently raises the model so that the new low point is actually on the plate. No warnings or error messages, and it's very intuitive to understand.

In addition, S3D also highlights the triangles/polygons rather than the full faces just as you've demonstrated above @TheThirdOne.

If it'd be helpful, I can do a quick video of how S3D handles this scenario.

TheThirdOne commented 6 years ago

Today I got it to a point where the feature can actually be used.

demo

I tested it with the model @qknight suggested, and there were some major framerate problems. When the model was first loaded it took several seconds to become responsive (presumably because I am populating a large array in perl). Additionally, even when not hovering over the model it was still slow.

This shows two major optimizations that almost certainly will need to be made. Only looking up the face for the currently hovered model and perhaps loading the color buffer in CPP.

Switching over to thinking about the UI. I found that on the d20, it was really easy to just use a triangle as an indicator, but that doesn't work on larger, more complex models. The triangles are simply too small. I didn't really have any indicator for what I was selecting.

Currently, the model will be pushed up so the lowest part of the model touches the bed. After looking through that code, I don't see an easy way to allow a part of the model to remain under the bed.

TheThirdOne commented 6 years ago

I haven't fixed the startup freeze, but I have fixed the framerate after the first frame. I realized that I was copying the color data every frame, and fixing that made it a lot better. But with 10 complicated models, it was still quite slow. Making it so the face check only applies to the hovered model alleviated that problem.

I then ran into what I think is a variation of #4420 where if I click the rotate face button three times it seg faults. I couldn't track down what the cause of the seg fault was though.

foreachthing commented 6 years ago

Question(s): Would it not be more "natural" to select "Rotate Face" first, then the desired face? Because if I want to do something else, like scale the model, I'd end up with a selected face first; even though I want to scale the whole model. ... And you don't actually rotate the face, do you? ;-)

MoonshineSG commented 6 years ago

Yes, select function then face

TheThirdOne commented 6 years ago

I definitely agree that selecting "Rotate Face" then selecting the face is more natural, but I don't think it is technically feasible to to have it operate on the main 3d scene that way. It would require keeping the state of whether the "Rotate Face" button had been selected and disabling other features if it had. Though, if I can do it in a maintainable way, this is the obvious choice.

I am not sure whether the current method or the more natural way but in a new window (like cut and layer heights) is more natural though. One thing to note is that with the current solution, if there are other operations that need a face / plane, it would be easy for them to be added. If anyone feels strongly one way or the other, I would like to hear it.

@foreachthing, I'm not sure what you meant by "... And you don't actually rotate the face, do you? ;-)". If it was a joke about the label "Rotate face", a better label hasn't come to my mind, but I am very open to suggestions.

foreachthing commented 6 years ago

@TheThirdOne, well no, not a joke! But you do rotate (home, align, drop, zero...) a BODY or model. If you edit a mesh, then you'd rotate a face...

Craftware calls it "drop plane": image

robbycandra commented 6 years ago

Hi... @TheThirdOne , your software above is interesting. Do you have any link to it ?

TheThirdOne commented 6 years ago

@robbycandra, I've been working on my fork of slic3r;

TheThirdOne commented 6 years ago

Now face selection pops open a dialog.

separate

I noticed that doing it this way also allows some additional options such as the plane to align the face with. Currently its not implemented, but its just a matter of adding in some more rotations behind an if.

My next steps will be to work on the aesthetics of face selection. At a minimum, I will be aligning the hover and selection colors with Slic3r's color scheme, but I will probably try to use a plane like what's in the cut dialog.

lordofhyphens commented 6 years ago

@TheThirdOne in your dialog, could you suppress the color highlight for the entire object and use that for the face selection? Since it should be the only model there, it should be expected to re-use the select color for just a face. Saves you from having to find another contrasting color.

lordofhyphens commented 6 years ago

@TheThirdOne It's moving along enough that I think you can (and should) open a pull request against Slic3r/Slic3r soon. That will start exercising some of the build servers and let me take a closer look at your work and start the review process when you indicate it's ready to be looked at seriously.

TheThirdOne commented 6 years ago

@lordofhyphens: About the selection color, that was the plan. I'll open a pull request when I go through the dialog a bit more (so probably end of tomorrow).

TheThirdOne commented 6 years ago

I implemented the selection color stuff that was discussed. I took a quick look to see what it would take to reuse the plane rendering used in the cut dialog; that code not reusable for planes not already aligned with the axes.

I then started working on making it so that ctrl-z doesn't have to be hit twice to undo it. Currently it does because I am just doing two rotations under the hood.

There are two ways that I could fit it into the current undo/redo system:

  1. Make it so rotations can operate about arbitrary axes (rather than just X,Y, or Z)
  2. Make an operation that groups two elementary operations so that be undone and redone together.

For this feature, 2 allows more flexibility, but I think that having 1 might allow some new features to be easier to implement. For example, rotating an object about the normal from the face might be useful and would be easy following from the code I have already done + option 1. I don't know exactly what 2 might be used for, but it seems generally useful.

I started checking out how 2 would need to be implemented, because from what I can tell 1 requires a lot of modification to do.

foreachthing commented 6 years ago

First of all: Great job!

Nevermind. Suggestion: Now you can rotate a face down onto the plate... how about an option where you can rotate a face up? Maybe I need this face to be extra-clean but can't be on the plate. Or maybe this face is off by just a few degrees but needs to be parallel with Z. Just a thought!

MoonshineSG commented 6 years ago

Isn’t there a “flip” function in Slic3r ?

foreachthing commented 6 years ago

@MoonshineSG, well, you're right! First, align the face to the plate, then rotate it (around X or Y) by 180°.

TheThirdOne commented 6 years ago

I implemented the group undo internal feature. It works swimmingly. I was able to get the dialog plane select to actually work as well.

However, I kept hitting crashes do to thumbnail stuff. So I spent some time working on #4420 because without some fixes, the extra rotations guarantee a crash with rotating to align with the xz or yz planes.

TheThirdOne commented 6 years ago

Spent more time investigating 4420. I made a quick fix to make it so that this feature doesn't crash, but I haven't solved the issue really.

All that is really left before this is complete it finishing up the UI. So what should this feature be called on the toolbar? Drop plane and rotate face are two options that have been previously mentioned. Additionally, what should the icon for this look like?

lordofhyphens commented 6 years ago

For the icon, maybe a octahedron with a colored face and a small arrow indicating the face is moving? Might be too busy, though.

lordofhyphens commented 6 years ago

"Rotate to face" for a name, perhaps?

mariusstrom commented 6 years ago

Simplify3D calls this "Place surface on bed", menu-exposed only (no icons).

gege2b commented 6 years ago

just a quickly made icon based on @lordofhyphens idea (full size and 16x16) oh and this is not a octahedron :D

rotate to face slic3r rotate to face slic3r_16x16

VanessaE commented 6 years ago

Way too much detail for the size, imho. How about a tetrahedron, rotated off-axis a bit (so that no face looks like it points straight down) instead?

VanessaE commented 6 years ago

Something like this maybe? 256px: image

32px: image

xoan commented 6 years ago

New icons should be based on Silk Iconset to maintain the current look and feel.

Probably by using a mix between some block icon with a colored face and an arrow.

PS. Not at home at this moment, so I can't do it now.

TheThirdOne commented 6 years ago

I did a bit of work on top of @VanessaE's idea. As it was it took up too much space within the 32x32 to fit in with the other icons. So I scaled it down, moved the arrow out to the right and changed the colored face to red. Then I added a blue plane to the bottom.

256px: rotate_face

32px: rotate_face

In the toolbar (colored): toolbar

In the toolbar (uncolored): toolbar-uncolored

I think this is pretty close to done. I think the colors could be adjusted a bit to fit in better, and size (and arrangement) could be modified a bit too. I also think it might be better without the black lines; they don't come through well when scaled down. However, I would to get some feedback from yall before I continue.

lordofhyphens commented 6 years ago

This will be in the next round of builds on https://dl.slic3r.org/dev

gege2b commented 6 years ago

I gave it a quick try and it seems to work as expected

the only problem I can see is the icon witch is twice the size (compared to the others) on windows 10

image