Page MenuHome

Added 3D Print -> Align to XY Plane button
ClosedPublic

Authored by Jaggz H (jaggz) on Nov 3 2021, 9:04 PM.

Details

Summary

Allow an object to be rotated so one face/selection can lie flat -- parallel to the -- XY plane. This is useful for 3d printing setup. The button is added in the 3d Print tools addon, in the transform section.

Here's a video of it in use:
https://www.youtube.com/watch?v=XF7_t70MA88

Diff Detail

Repository
rBA Blender Add-ons
Branch
arcpatch-D13094
Build Status
Buildable 19716
Build 19716: arc lint + arc unit

Event Timeline

Jaggz H (jaggz) requested review of this revision.Nov 3 2021, 9:04 PM
Jaggz H (jaggz) created this revision.
Jaggz H (jaggz) edited the summary of this revision. (Show Details)Nov 4 2021, 6:49 AM

Added comments

You might want to add reviewers otherwise it will stay in the limbo.

You might want to add reviewers otherwise it will stay in the limbo.

Campbell is the author of 3D-Print ToolBox. So add him as a reviewer?

Jaggz H (jaggz) edited the summary of this revision. (Show Details)Nov 27 2021, 9:42 PM
  • Rotation now handled properly
  • Rotation now handled properly

Okay, got it using proper rotation setting instead of relying on parenting to an empty.

This seems like a useful feature, some requests.

  • Accumulate normals of all selected faces instead of picking just the active face (scaling by the area will give slightly better results).
  • Use edit-mode mesh, from BMesh since the mesh in obj.data may not be in sync.
object_print3d_utils/operators.py
753

This should pick the active object.

756–757

There should be a check for the active face not existing.

  • Allow multi-face, and multi-object use
Jaggz H (jaggz) marked 2 inline comments as done.Dec 9 2021, 5:23 AM

Okay, I made some changes (I think Campbell's comments don't line up with the line numbers anymore).
It now loops through all selected objects so a user can handle many at once.
It also averages the selected faces' normals, should a user desire that.
I'm not sure if it's appropriate, but if they're in edit mode, I toggle out to get selection changes updated (and then back in).
(I'm sure there's some way to access the data in edit mode, but I couldn't find it just yet.)

  • Allow multi-face, and multi-object use
  • Allow multi-face, and multi-object use
Campbell Barton (campbellbarton) requested changes to this revision.Dec 13 2021, 7:35 AM

Since this operator uses face-selection it should use the edit-mesh without toggling edit mode, see existing code that uses bmesh.from_edit_mesh.

object_print3d_utils/operators.py
758

Use context.objects_in_mode_unique_data

768–769

There is no need to change to rotation mode.

Instead, you can set the matrix_world of the object, which will handle writing to the appropriate channels.

You'll need to backup/restore the location & scale values if you're assigning matrix_world directly,
otherwise you could read the matrix, rotate it then set it back.

This revision now requires changes to proceed.Dec 13 2021, 7:35 AM

Since this operator uses face-selection it should use the edit-mesh without toggling edit mode, see existing code that uses bmesh.from_edit_mesh.

In addition, I thought it'd be intuitive if the user could also select faces in objects, leaving them, and rotating them all in Object mode. (Use case: Maybe they work on them one by one, not entering Edit mode with all of them selected, then they go into object mode, select all the ones they want to rotate (with the faces now having been selected), and click the Align button...)

If you approve of that, I believe I'd then need to handle both, using from_edit_mesh if we're in edit mode, and the current method if in object mode would be most efficient? (vs. getting the mesh, making a new bmesh, and using bm.to_mesh(me))

  • Rotation working. Face normals in. Edit and Object mode functioning
  • Rotation working. Face-area normalization. Edit and Object mode functioning.
Jaggz H (jaggz) updated this revision to Diff 46525.EditedJan 3 2022, 12:18 AM
Jaggz H (jaggz) marked 2 inline comments as done.
  • Rotation working. Face normalization is in. Edit and Object mode both functioning
Campbell Barton (campbellbarton) requested changes to this revision.Jan 9 2022, 6:29 AM

Thanks for the update, think this is close to being finished.

Some notes, while I don't have such strong opinions on exactly how this is done, the current state of this operator seems a bit awkward.

  • Using face-selection in object mode seems strange - other 3D print operators (such as reporting volume) make sense to run an object mode. This operator however requires a selection logically - so I don't think it makes sense to expose it at all in object mode (unless we limit it to vertex-paint/texture-paint which do support face selection - although this seems like a very obscure use case).

    Suggest to limit this to edit-mode only.
  • Face area weighting option in the UI seems cramped, why not remove the option and always use face-area?
object_print3d_utils/__init__.py
61–65

I'd rather this be an operator property, using area weighting is a good default and probably what people want most of the time, I don't think this option needs to be exposed in the UI.

object_print3d_utils/operators.py
747

In this case I'd rather avoid the reference to Object->Transform->Align Objects - this kind of information gets outdated and makes this tip overly verbose.

778–780

Wrap for body onto separate line.

781

Check normal isn't zero, this might not have expected behavior (there is no need to rotate in this case).

783

Spaces between commas.

822

Prefer not to add editor spesific configuration to each file.

This revision now requires changes to proceed.Jan 9 2022, 6:29 AM

Thanks for the update, think this is close to being finished.

Some notes, while I don't have such strong opinions on exactly how this is done, the current state of this operator seems a bit awkward.

  • Using face-selection in object mode seems strange - other 3D print operators (such as reporting volume) make sense to run an object mode. This operator however requires a selection logically - so I don't think it makes sense to expose it at all in object mode (unless we limit it to vertex-paint/texture-paint which do support face selection - although this seems like a very obscure use case).

In testing the workflow, I was considering that highly (and knew we'd end up in this discussion). Now, while it's not common (if at all) in Blender -- to utilize the "internal" (edit mode) selection, when it's not visible/obvious in Object mode, the workflow was one which made sense. I evaluated and realized that people would definitely go from object to object, selecting the face they wanted, then re-select them *without taking them *all* into edit mode*, which is actually a hinderance in many cases (especially when rotating around and trying to select things), so it seemed like "violating" the contemporary approach was actually a much more useful approach and (as I'll explain) more-intuitive than the alternative. The other interesting thing is that we're rotating the object, not the mesh -- which is another weird thing to do in edit mode. And since providing it is then going to be awkward in that way, which one do we want to violate? I figured I'd side (in favor) with the side of the one that offered the most convenience AND met user expectations (if they select a bunch of objects and click the button, they expect them to flip (rotate) -- so the behavior is not unintuitive either, imho). </phew>

Suggest to limit this to edit-mode only.

Also, 3d print already has the "check all", and stuff, in Object mode, including things like recording the set of overhanging faces, so this isn't a completely inconsistent ability, given the value and convenience (I think) that it imparts.

  • Face area weighting option in the UI seems cramped, why not remove the option and always use face-area?

I also did not ignore that -- however, I realized that me, and many others, might work on faces, where they have set normals.
Imagine an asymmetric object with two faces, each at 45 degrees to the [final] XY plane. Yet the faces are different sized.

Pic of example:

  • Point taken re: face area, it can stay an option, still feels cramped in the UI though which would be good to resolve.
  • I'm not convinced this is useful to expose in object mode. Using selection in a context the selection it's self is not visible is bad for usability (the user needs to enter edit-mode to see what's going to be done). The "check all" operator doesn't read the face selection in object mode, you may enter edit mode and set the selection which is quite different.
  • Rotation working. Face normals in. Edit and Object mode functioning without context switch. Added FIXME notes to operator
object_print3d_utils/operators.py
746

Did you try

789

Could you keep the translation component of the object? (suggest to backup/restore the objects location).

  • Restored object loc and size

Okay, except the fixme for Undo, I think this is a usable version. LMK. :)

Minor cleanup to D13094

  • Remove VIM configuraiton.
  • Shorten line length.
  • Run autopep8
  • Use continue to early exit out of the loop.
This revision is now accepted and ready to land.Feb 15 2022, 5:57 AM

Committed rBe648555eb6b11be56b08f2d10a16c3782271df92