5
$\begingroup$

NOTE: I've updated progress at the bottom of the question, so some of my initial issues have been later resolved.

I'm trying to create a Geometry Node group that applies a square cutout pattern to objects (flat plates). So far, I have managed to create a static pattern that works fine if the object is aligned with the global axes, but it doesn't work if the part is rotated.

What I (believe I) need is a vector that describes the long edge of the part. From this, I can find the rotation angle. I tried the bounding box node, but that gives me a box that is aligned to the axis, not one that represents the minimum (smallest) bounding box for that shape. I could also extract the longest edge, but I'm not sure how to do this either.

EDIT: I should add, the geometry is imported from CAD, so I believe it is similar to moving and rotating an object and then applying transformations. I have added an image to better explain the two bounding box methods. Blender's Bounding Box node uses the axis-aligned method, whereas I need an object-aligned method - that is the smallest box that will fit around the object.

Any suggestions?

Example shapes (x2) aligned with axes - the geometry nodes work fine here:
Example shapes (x2) aligned with axes

Example shape, NOT aligned with axes:
Example shape, NOT aligned with axes

Geometry Node Setup:
Geometry Node Setup

Bounding Box example:
enter image description here

EDIT: Strictly speaking - the original question (minimum bounding box or longest edge vector) has been answered (and accepted), however, it has prompted further questions. Please let me know if these should be split off into a separate SE post.

Following on from quellenform's response, I've made further progress. Here's what I've changed.

  • The convex hull node was useful for determining the rotation angle, but the longest edge calculation needs to be defined from the aligned bounding box, since the longest edge of the original shape may not correspond to the longest dimension (consider an equilateral triangle shape - the height is greater than any single side). To solve this, I used the rotation angle, to rotate the original geometry, apply the bounding box, then extract the longest and shortest sides.
  • New Problem - The longest edge may be a mesh diagonal, not a sharp edge. How can I filter the longest edge calculation to include edges with an 'edge angle' over some threshold?
  • New Problem - The rotation angle calculation for some objects needs to be calculated to the X axis, whereas for other objects it needs to be calculated to the Y axis. How can I automate this selection?
  • New Problem - The origin point for the original geometry is not always centred on the bounding box. To correct this, I've calculated a translation vector based on the aligned bounding box of the original geometry and the bounding box of the grid. This seems to work, but in many case it aligns close, but not exact. How do I resolve this?

Summary:

  • How do I filter edge calculation for sharp edges only?
  • How do I automate the axis selection for angle rotation?
  • How do I correct the translation for the grid?

File Upload:

  • This is an updated example file with many more sample shapes and updated geo nodes tree.
$\endgroup$
8
  • $\begingroup$ Maybe helpful: blender.stackexchange.com/a/274008/145249 $\endgroup$
    – quellenform
    Aug 29, 2023 at 0:30
  • $\begingroup$ This appears to be using the standard blender bounding box node, which is axis aligned. I need it to be the minimum bounding box (object aligned). Once we get that, then yes, I could work with the rest of your example. $\endgroup$
    – G.H.
    Aug 29, 2023 at 0:55
  • $\begingroup$ Edited to explain the bounding box types, and that this geometry has been imported from CAD. $\endgroup$
    – G.H.
    Aug 29, 2023 at 1:02
  • $\begingroup$ Stupid question: Why don't you create the geometry unrotated, then add your Geometry Nodes, and rotate the object only at the end? Or you create the mesh unrotated and rotate it via Transform, because with that you could read the rotation. $\endgroup$
    – quellenform
    Aug 29, 2023 at 8:34
  • 1
    $\begingroup$ ...I would suggest you create a follow up question from your added changes, otherwise it goes beyond the scope and this question loses focus here. $\endgroup$
    – quellenform
    Aug 31, 2023 at 8:56

1 Answer 1

4
$\begingroup$

TL;DR
The node Convex Hull creates the outer hull from a flat rectangular shape, which is also the object-aligned bounding box.

The following setup should get you there, assuming that:

  • The mesh is flat
  • The mesh is rectangular

enter image description here

To start, I use the Convex Hull node, which gives me back the original outer shape:

enter image description here

Then I remove the extrusion of the mesh so that I get a single rectangular (upper) face. I achieve this by comparing the normals of the faces with the upvector:

enter image description here

Then I separate the two longest and the two shortest edges from each other and determine their lengths:

enter image description here

By transferring the lengths of the first edge in each case (index $0$) with Sample Index, I can process this information further and use it to calculate the grid and the size of the cubes. After I have created the required objects from these values, I determine from the vector of the longest edge and with the help of Align Euler to Vector additionally the rotation that I need to align these objects correctly. Then I simply instantiate the cubes at the points of the grid:

enter image description here

And the final result looks like this after Mesh Boolean:

enter image description here


(Blender 3.6+)


Update

If the points of the upper surface are not exact on a plane, the node Convex Hull may add an additional diagonal edge.

You can avoid this problem by either editing the mesh and making sure that all points are exactly on one plane (select the points of the upper face in Edit Mode and press S > Z > 0), or you can either move the points there in Geometry Nodes, or remove the extra diagonal edge.

This might look something like this:

enter image description here

$\endgroup$
6
  • $\begingroup$ This is great. It seems to be tolerant of object shape (trapezoid, triangle or irregular polygon instead of a rectangle), but it seems to be intolerant of orientation (direction of the long edge). I think I've traced the problem to the 'Align Euler to Vector' node. The grid that was constructed was not always aligned with the base object. I'm not sure how to resolve that though - any suggestions? $\endgroup$
    – G.H.
    Aug 29, 2023 at 11:11
  • $\begingroup$ @G.H. After all, your example only shows a rectangular mesh. What other shapes are there? For this, it would be good if you shared your blend file (blend-exchange.com) so we can take a closer look and possibly supplement the question with more information. $\endgroup$
    – quellenform
    Aug 29, 2023 at 11:15
  • $\begingroup$ The shape is fine, but the rotation of the shape seems to have a problem. Here's an example with a rectangle that has the problem. blend-exchange.com/embedImage.png?bid=MKjGg7AR For what its worth, the model is representative of a rectangular sheet of material which may or may not have cutouts - which means there is a maximum size (rectangle) but any shape (polygon) smaller than the original rectangle may be valid. $\endgroup$
    – G.H.
    Aug 29, 2023 at 11:52
  • 1
    $\begingroup$ @G.H. Ah, all right, that has to do with the fact that the points of the upper face are not exact on a plane. Select all four points of the upper face in Edit Mode and scale their Z-position to 0 (S > Z > 0). If the points are not exactly on one plane, the node Convex Hull will create an additional diagonal edge (which of course will be the longest edge of the mesh), and therefore you will not get a correct rotation. $\endgroup$
    – quellenform
    Aug 29, 2023 at 12:01
  • $\begingroup$ I've accepted this as the answer because the answer lies within your blender file, however, your description is oversimplified. The process I used (with your help) was to calculate the longest edge and its rotation angle, then use this angle to rotate the original geometry, calculate the bounding box (since its now aligned) - this gives me the length and angle of the longest edge and the dimensions of the aligned bounding box. $\endgroup$
    – G.H.
    Aug 31, 2023 at 4:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .