Hi! I have a mesh (straight cylinder or other).
I deformed it with the help of WPO. I shifted it in space and bent it.
The green arrows are the original mesh vertex normals.
How to find a new direction of vertex normals (yellow arrows) for a deformed mesh with material shader.
I know directions at every point (red arrows).
If you know the red arrow vector, the normal is fairly trivial to find. The red arrow is the tangent, and the normal is always simply 90 degrees (aka orthogonal) from the tangent.
If your curve is 2D as you depicted then one simple trick to rotate a vector by 90 degrees clockwise is to take the (X,Y) value of that vector, multiply the x by -1 and then do an yx swizzle. The new vector will be equal to (Y,-X).
Cross products, and derivatives can also be useful for finding orthogonal vectors, especially if the curve is 3D. For example, the normal of a Bezier curve function is equal to its derivative.
It’s 3D.
Yes, I’m using bezier curves. I bend the cylinder like a bezier curve.
template< class T, class U >
static FORCEINLINE_DEBUGGABLE T CubicInterp( const T& P0, const T& T0, const T& P1, const T& T1, const U& A )
{
const float A2 = A * A;
const float A3 = A2 * A;
return (T)(((2*A3)-(3*A2)+1) * P0) + ((A3-(2*A2)+A) * T0) + ((A3-A2) * T1) + (((-2*A3)+(3*A2)) * P1);
}
Direction (normal=red arrow) I calculate as the first derivative of the bezier curve equation.
template< class T, class U >
static FORCEINLINE_DEBUGGABLE T CubicInterpDerivative( const T& P0, const T& T0, const T& P1, const T& T1, const U& A )
{
T a = 6.f*P0 + 3.f*T0 + 3.f*T1 - 6.f*P1;
T b = -6.f*P0 - 4.f*T0 - 2.f*T1 + 6.f*P1;
T c = T0;
const float A2 = A * A;
return (a * A2) + (b * A) + c;
}
I can find cross product direction (normal=red arrow) and the global UP vector, which will give me a some orthogonal vector.
I still can’t add volume or thickness to the spline after deformation.
The up vector cross products gives you a normal, but technically a 3D Bezier curve has infinite coplanar normals at any point. If you want to expand a mesh away from this point, you will need to expand each point along a different normal.
Now that you have one normal, you can rotate that normal about the tangent axis to get any other normal you may need to expand along.
In a similar project, I encoded the mesh UVs in a manner that allowed me to target what direction the vertex should expand.
You may also be interested in the “spline thicken” node. It’s not well documented, but it is designed to expand a ribbon in view space, and uses camera tricks and a normal map to create the illusion of thickness.
My current version looks like:
I find a cross product between the direction at the current point of the spline and the some up vector. This is some spline normal (orthogonal vector to the direction).
I rotate the normal 0…360 degrees to find the normal at each point.
Sometimes there is an incorrect cases
Thanks. I’ll try to read about “spline thicken” node