2
$\begingroup$

I have a Curve. It contains lots of splines.

(Here I simply take two splines as an example) enter image description here

Now i extrude it. enter image description here

Now i want make all the extrusion face the camera. That is,I want all spline extrusions to rotate along the spline axis when the camera rotates.(to simulate the cylinder effect in the camera view)

Any help will be appreciated.

$\endgroup$
2
  • $\begingroup$ This might be possible with geometry nodes, but I imagine it would be very complex. Why not just make them actual cylinders? $\endgroup$
    – TheLabCat
    May 24 at 2:56
  • $\begingroup$ @TheLabCat Cause I have millions of splines, it takes more time to render if I bevel it to cylinders. Could you please tell me how to do it with geometry nodes? $\endgroup$
    – Tac
    May 24 at 4:04

1 Answer 1

8
$\begingroup$

Is this what you want?

extruded curves facing camera

I made that with the Geometry Nodes Modifier.

Geo Nodes

This node tree will extrude any spline. The extrusion is oriented to the camera while still following the curve tangent.

What it does is create a face line position it in the curve points with an offset to the sides, the sides being the $X$ axis of a rotation in which the $Z$ axis points to the camera, while the $Y$ axis points to the curve tangent.

$$\text{The Way It Works}$$

First, a grid is created. Y vertices = $2$; X vertices = curve's point count.

grid

That way, it's vertices are ordered as this image shows:

grid points order

The grid's vertices are ordered as: indexes $0$ and $1$ are for right and left of the curve point with index $0$; indexes $2$ and $3$ are for right and left of the curve point with index $1$; and it goes that way for all...

Now it needs to set the vertices of the grid to the curve position using the index to select the curve point. For a point in the grid, it's position is set to the position of the curve point with index equal to $\lfloor i \mod 2\rfloor$ where $i = \text{vertex index}$. The position is accessed using a Transfer Attibute Node with the curve as source and index as mapping.

enter image description here

Now the pair of vertices of every curve point is in the curve point's positon. The next step is to offset them to the extrusion direction, which is calculated by the following way:

For a point in the curve, a vector pointing to the camera is calculated by subtracting the point position from the camera position. After that, the vector is used to create a rotation that points the $Z$ axis to the camera. Then it aligns the rotation's $Y$ axis with the curve point's tangent, here it uses the $Z$ axis as pivot so it doesn't change.

Rotation to Camera

the resulting rotation's $X$ axis, now points to the side in relation to the camera and curve direction.

Now the vector $(0.5, 0.0, 0.0)$ is rotated with the calculated rotation, this is now the extrusion direction. $X$ is $0.5$ because the curve point is the extrusion center, so the left and right vertices needs to be transformed by half the extrusion length, but opposite directions.

extrusion direction

Now for offsetting the vertices of the grid, we first transfer the offset from the curve's points using the same way as for positions.

enter image description here

Before plugging the extrusion direction in the offset socket, it is first multiplied by: extrude length, if vertex is from right side; If not, negated extrude length.

Now faces are facing the camera, but, if there's multiple splines, they will be connected:

enter image description here

These connecting faces needs to be deleted, so a way to is needed.

First, the spline index is captured in the curve, with that it's possible to tell from which spline a point comes from.

A face connecting splines is the last face of it's spline index, so we can select them by verifying if the spline index of the next face is different.

select faces connecting splines

And finally faces are deleted using the selection of connecting faces.

deleting faces connecting splines

$\endgroup$
5
  • $\begingroup$ Oh my god, this is exactly what I want! Thank you so much. Could you please help me to explain its theory? $\endgroup$
    – Tac
    May 24 at 6:15
  • $\begingroup$ @Tac no problem. I added an explanation to the answer. I also corrected an error and made a change in the nodes. The blend file was also updated. $\endgroup$
    – Hulifier
    May 24 at 8:46
  • $\begingroup$ I am making note of this answer to be part of my continued math class when I am awake enough to read and understand all of it. $\endgroup$
    – TheLabCat
    May 24 at 11:58
  • $\begingroup$ Thank u very much!! You are so kind!! Sorry to disturb you, but when I tried to make this complex geometry nodes group link to a new file (That is make it a node template) and changed the camera, there was a problem with curve extrusion in the new file. It has the wrong direction and will twist. Thank you very much for your help and sorry to bother you again.@Hulifier $\endgroup$
    – Tac
    May 26 at 14:51
  • $\begingroup$ @Tac I fixed and error in the nodes, the Object Info Node for the camera was in Original mode, but it should be Relative, sorry for that. See if changing that fix it. I updated the file and the images in the answer. $\endgroup$
    – Hulifier
    May 26 at 17:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.