From 036919d692fda532bfba508f77ea9dba37d5c4f9 Mon Sep 17 00:00:00 2001 From: yum Date: Sat, 6 Dec 2025 19:09:42 -0800 Subject: begin work on "un-tube" feature essentially the inverse of the sheet -> tube transform. --- vertex_deformation.slang | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) (limited to 'vertex_deformation.slang') diff --git a/vertex_deformation.slang b/vertex_deformation.slang index 047f7d7..577b0d2 100644 --- a/vertex_deformation.slang +++ b/vertex_deformation.slang @@ -84,7 +84,7 @@ float3x3 inverse(float3x3 m, float det) { return inv; } -// Takes map a 2x2 quad on the xy plane to a tube. The circular cross section +// Maps a 2x2 quad on the xy plane to a tube. The circular cross section // is on the xz plane. [Differentiable] public float3 plane_to_tube(float3 xyz, no_diff float t) { @@ -93,7 +93,8 @@ public float3 plane_to_tube(float3 xyz, no_diff float t) { float z0 = xyz.z; float theta = x0 * PI; - float phi = z0 * PI; + + // Equivalent to (1 / (|t| + eps)) * sign(t) float radius = 1.0f / (dabs(t) + 1e-4f) * sign(t); float x = sin(theta / radius) * (radius * PI_RCP - z0); @@ -114,6 +115,40 @@ public void plane_to_tube_undeform_normal(float3 xyz, inout float3 normal, R3R3_UNDEFORM_NORMAL_AND_TANGENT(normal, tangent); } +// Maps a tube with circular cross section on the xz plane to a quad on the xy +// plane. +[Differentiable] +public float3 tube_to_plane(float3 xyz, no_diff float t) { + float x0 = xyz.x; + float y0 = xyz.y; + float z0 = xyz.z; + + float theta = atan2(z0, x0) - PI; + float r = length(float2(x0, z0)); + x0 = r * cos(theta); + z0 = r * sin(theta); + + // Equivalent to (1 / (|t| + eps)) * sign(t) + float radius = 1.0f / (dabs(t) + 1e-4f) * sign(t); + + float x = sin(theta / radius) * (radius * PI_RCP - z0); + float z = (1.0f - cos(theta / radius)) * (radius * PI_RCP) + cos(theta / radius) * z0; + + return float3(x, y0, z); +} + +public void tube_to_plane_normal(inout float3 xyz, inout float3 normal, + inout float3 tangent, float t) { + R3R3_NORMALS(xyz, normal, tangent, tube_to_plane, t); +} + +public void tube_to_plane_undeform_normal(float3 xyz, inout float3 normal, + inout float3 tangent, float t) { + R3R3_DECLARE_BASIS_VECTORS(xyz); + R3R3_AUTODIFF_BASIS_VECTORS(tube_to_plane, t); + R3R3_UNDEFORM_NORMAL_AND_TANGENT(normal, tangent); +} + [Differentiable] public float3 seal(float3 xyz, no_diff float A, no_diff float k, no_diff float t) { float x = xyz.x; -- cgit v1.2.3