3
$\begingroup$

Sonic 3D model filled with LEGO brick 3D models.

This was done using a script; however, could there be a way to achieve this effect with geometry nodes?

$\endgroup$
4
  • $\begingroup$ You mean something like this? entagma.com/pack-points-inside-objects-with-geometry-nodes He uses spheres, but if you have something like a Lego piece in mind, it would be even simpler since you wouldn't have to trigonometry, just box size calculations. $\endgroup$
    – Kuboå
    Commented Mar 25, 2022 at 21:30
  • $\begingroup$ @Kuboå That's actually really close! I don't know how I'd make the necessary changes though. The node setup he used is incredibly complex. $\endgroup$
    – Zacharoth
    Commented Mar 25, 2022 at 21:41
  • 1
    $\begingroup$ Imagine you create a curve line, resample it to create points along its length. That's easy enough. Then you make a vertical one and distribute the previous line on that. And do this for a third one on the Y axis. Then "Instance on Points" your legos. You have a big cube packed with legos. Now you just need to use Raycast to check if they're inside your mesh or not, delete the ones outside. Here's a tut for that: youtube.com/watch?v=tvb2aCeTANM If noone else answers I can put sth together tomorrow evening after work, but I need to go to bed now. Good luck. $\endgroup$
    – Kuboå
    Commented Mar 25, 2022 at 21:51
  • $\begingroup$ I integrated a solution based on raycasts inspired by the comment of @Kuboå into my answer $\endgroup$ Commented Mar 27, 2022 at 7:03

1 Answer 1

3
$\begingroup$

This is my solution. I filled an icosphere with lots of small cubes. It would work the same with other objects:

enter image description here

And here rendered with a finer resolution: enter image description here

I tried two different setups. One works with intersection, the other uses a Raycast node inspired by the comment of @Kuboa in a slightly different way.

This is the setup, that uses intersection:

intersection setup

And this is the setup, that uses the Raycast node: raycast setup

The included node group looks like this: Group node: Is Point in Object?

And here are my blend files:

How does it work

I will first describe the solution, that uses intersection. After that, I will describe the solution, that uses the Raycast node.

Using Intersection

My strategy is to create a grid and scan the body from bottom to top. Doing this, I create the intersection between the grid and the volume for every position of the grid. After doing this, I simply instantiate cubes at every point of the resulting geometry.

Here we go step by step: The size for the scanning grid and its resolution are given as input parameters. I used a size of 3 with a resolution of 0.1 (0.03 for the rendered image) in every direction, while the icosphere has a radius of 1. The number of vertices of the grid are calculated by dividing the grid size by the resolution.

Grid

In order to scan from bottom to top, a mesh line with the given resolution is created:

Mesh Line

Then I create instances of the grid along this grid line:

instantiating the grid

The resulting instances are realized and intersected with the sphere:

intersection

Finally, I create cube instances of the size defined by the resolution on every point of the intersection. In order to prevent artifacts, the geometry of the sphere is excluded by selecting only those points, that have the same position as the closest point of the generated stack of grids.

creating cube instances

Using Raycasts

This solution starts with the same grid, as the solution before:

grid

Then, cubes are generated on those points:

enter image description here

Only those points will be used for instancing, that are inside the Ico Sphere:

selecting points

Let’s have a look inside the group node “Is Point in Object?”

Group node: Is Point in Object?

Here we need some vector algebra, to understand what's going on. Subtracting the vector of a point P1 from the one of a point P2 results in a vector pointing from P1 to P2. This is used to create a ray starting at the point given by the group input and pointing into the direction of the closest point of the target object.

The ray will point inside the object, if the starting point is outside and vice versa. The normal of the point, that is hit on the object will always point outside the object. This means, the starting point of the ray is inside the object, if the angle between the ray and the normal of the point, that is hit on the object, is less than 90°. The dot product of two vectors is greater than 0, if their angle is less than 90°. Thus, the starting point is inside the object, if the dot product between the direction of the ray and the normal is greater than 0.

ray

$\endgroup$
2
  • 1
    $\begingroup$ I'll note that this method includes the vertices from the intersected mesh as well, which causes artifacts on the surface--which is really the only part that matters. It does work on the inside, but their needs to be a way to get rid of the points that came from the icosphere. $\endgroup$
    – lwswl
    Commented Mar 25, 2022 at 22:55
  • $\begingroup$ @LWS SWL - I limited the selection of points to those, that belong to the original stack of grids and updated the description. $\endgroup$ Commented Mar 25, 2022 at 23:38

You must log in to answer this question.

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