0
$\begingroup$

I have a complex Bézier curve object (20k control points), with all points in the XY plane.

I have a complex terrain mesh (20M faces), which is (mostly) a grid in the XY plane, with varying heights on the vertices.

I want to edit the curve object, and move each control point down (-z only) until it is sitting on the mesh below. Like dropping wet spaghetti onto the ground. Draping the curve over the mesh. (Though, to be fair, I said "-z only", which means the lengths of these strands will change. That's desirable; I don't want a physically-accurate simulation that preserves strand length, or lets the noodles slide down the side of a mountain.)

Does Blender have a mechanism for doing this (other than a ~complex script and a lot of processing time)?

3D terrain with mountains, with many blue tubes in a plane above it

Attached is a small test bed from the overall model:

$\endgroup$
2
  • 1
    $\begingroup$ Sorry I cannot write a full answer right now, but try searching for the Raycast node in Geometry Nodes, that should do what you want. $\endgroup$ Commented Aug 19 at 20:23
  • $\begingroup$ @GordonBrinkmann Thanks, looking now. $\endgroup$
    – Phrogz
    Commented Aug 19 at 20:26

2 Answers 2

1
$\begingroup$

I added a cube to the scene and gave it Geometry Nodes modifier, this way the GN object is independent from the source objects "terrain" and "Simple_trails".

The curve object "Simple_trails" had a Bevel on it to make it a tube. I got rid of that because otherwise it will be treated as a mesh object.

I imported the source objects both with Object Info nodes set to Relative (that's important). Then I plug the "terrain" into the Target Geometry of a Raycast node, the Geometry of the "Simple_trails" into a Set Position node which gets the Position from the Hit Position.

Afterwards I used a Curve to Mesh node to convert the curve back to a tube appearance and gave it a material.

curve onto surface

Of course the curve can be resampled for a higher resolution if necessary and moved up or down by changing the Z value of the Offset.

$\endgroup$
2
  • $\begingroup$ Far more elegant! Thank you. I totally don't understand/did not expect the magic that somehow back-feeds the points from the geometry going into Set Position to the Source Position in the Raycast, but that's nice that it exists! The only caveat is that if one rotates the cube so that its local -z is not the same as global, the "down" ray direction is no longer valid. If one did that, I'd suggest it was perhaps intentional. :) $\endgroup$
    – Phrogz
    Commented Aug 21 at 17:57
  • $\begingroup$ @Phrogz Everything you do in Geometry Nodes is relative to the GN object's local origin, rotation and scale. This is not limited to the Raycast node. $\endgroup$ Commented Aug 21 at 18:25
0
$\begingroup$

As @GordonBrinkmann pointed out, the key is to use a Raycast node against the terrain mesh to find where the points ought to be. His solution is great and simple if your curve and terrain are free of transforms. (Edit: Wait! His solution is great even if the terrain and curve are transformed, because of his use of Relative mode. This requires the use of Object Info node on the curves as well. This answer is preserved just to show how much extra work is needed if you don't use Relative. :)

This first answer transforms the terrain and curve geometry into global space, performs the raycasting, and then transforms the hit point back into the local space of the curve:
Sampling Points from curve to feed into Source Position of Raycast

Edit: as noted in the accepted answer, this transformation magic can be automatically taken care of by using Relative mode on the geometries.

Alternatively, you can transform the geometry of the mesh into the local space of the curve. If you do this, and your curve object is rotated such that its local -z does not match the world -z, you'll also need to rotate your "down" vector to match:
enter image description here

Finally, for both answers: if your curve has enough control points that you just want to transform the original control points without resampling the curve, you can drop the Resample Curve node, and feed the original curve geometry along.

$\endgroup$
2
  • $\begingroup$ Your setup looks way too complicated... I'm not sure why all this is necessary. Take a look at my answer if this will work for you. $\endgroup$ Commented Aug 21 at 7:06
  • $\begingroup$ @GordonBrinkmann I'll accept yours, because it's delightfully simple for the no-transform case. As I've edited my answer to describe, these two solutions are only needed if the curve and/or terrain are transformed. Edit: Oh, now I understand the importance of Relative in your answer. Far better! $\endgroup$
    – Phrogz
    Commented Aug 21 at 17:44

You must log in to answer this question.

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