Skip to main content

lactea_render/
warp_mesh.rs

1// SPDX-FileCopyrightText: 2026 Gianluca Boiano
2// SPDX-FileCopyrightText: 2005-2013 Nullsoft, Inc.
3// SPDX-License-Identifier: (MIT OR Apache-2.0) AND BSD-3-Clause
4
5//! Warp-mesh geometry and MD2's per-vertex UV formula (milkdropfs.cpp
6//! `CPlugin::ComputeGridAlphaValues`, vertex setup in plugin.cpp `AllocateMilkDropDX9`).
7//!
8//! The engine evaluates per-pixel code (if any) for every grid vertex and hands the resulting
9//! variables to [`warp_vertex_uv`]; presets without per-pixel code use [`warp_mesh_uniform`].
10//! The result is the `warp_uv` grid in [`crate::FrameInput`].
11//!
12//! Conventions (identical to MD2):
13//! * grid is `(gx+1) x (gy+1)` vertices, row-major, **row 0 is stored at clip y = -1**
14//!   (bottom of the screen). UV `v = 0` is the top of the texture, so row 0 samples `v ~ 1`.
15//! * `x`/`y` are clip-space coordinates (`x*0.5+0.5` / `y*-0.5+0.5` are the preset-space `x`/`y`
16//!   seen by per-pixel code, before the aspect correction).
17
18use crate::RenderError;
19
20/// Static mesh data: vertex positions and MD2's `rad`/`ang` per-vertex attributes.
21///
22/// The grid has an even number of cells (>= 2) per axis; [`MeshGeometry::new`] enforces that, which is why the
23/// fields are private.
24#[derive(Clone, Debug)]
25pub struct MeshGeometry {
26    pub(crate) gx: u32,
27    pub(crate) gy: u32,
28    pub(crate) aspect_x: f32,
29    pub(crate) aspect_y: f32,
30    pub(crate) x: Vec<f32>,
31    pub(crate) y: Vec<f32>,
32    pub(crate) rad: Vec<f32>,
33    pub(crate) ang: Vec<f32>,
34    /// [`MeshGeometry::projectm_vertex`] of every vertex, indexed like `x`: constant for the mesh, so computed once.
35    pm: Vec<([f32; 2], f32, f32)>,
36}
37
38/// `(m_fAspectX, m_fAspectY)` from texture size (plugin.cpp).
39pub fn aspect_xy(tex_w: u32, tex_h: u32) -> (f32, f32) {
40    let ax = if tex_h > tex_w {
41        tex_w as f32 / tex_h as f32
42    } else {
43        1.0
44    };
45    let ay = if tex_w > tex_h {
46        tex_h as f32 / tex_w as f32
47    } else {
48        1.0
49    };
50    (ax, ay)
51}
52
53impl MeshGeometry {
54    /// Build the mesh of `gx x gy` cells for a `tex_w x tex_h` image.
55    ///
56    /// Fails with [`RenderError::Invalid`] unless both cell counts are even and at least 2 (MD2 builds the grid
57    /// from four quadrants).
58    pub fn new(gx: u32, gy: u32, tex_w: u32, tex_h: u32) -> Result<Self, RenderError> {
59        if gx < 2 || gy < 2 || !gx.is_multiple_of(2) || !gy.is_multiple_of(2) {
60            return Err(RenderError::Invalid(format!(
61                "mesh dimensions must be even and >= 2, got {gx}x{gy}"
62            )));
63        }
64        let (ax, ay) = aspect_xy(tex_w, tex_h);
65        let n = ((gx + 1) * (gy + 1)) as usize;
66        let mut g = MeshGeometry {
67            gx,
68            gy,
69            aspect_x: ax,
70            aspect_y: ay,
71            x: Vec::with_capacity(n),
72            y: Vec::with_capacity(n),
73            rad: Vec::with_capacity(n),
74            ang: Vec::with_capacity(n),
75            pm: Vec::with_capacity(n),
76        };
77        for y in 0..=gy {
78            for x in 0..=gx {
79                let vx = x as f32 / gx as f32 * 2.0 - 1.0;
80                let vy = y as f32 / gy as f32 * 2.0 - 1.0;
81                let rad = (vx * ax).hypot(vy * ay);
82                let ang = if y == gy / 2 && x == gx / 2 {
83                    0.0
84                } else {
85                    (vy * ay).atan2(vx * ax)
86                };
87                g.x.push(vx);
88                g.y.push(vy);
89                g.rad.push(rad);
90                g.ang.push(ang);
91                g.pm.push(projectm_vertex(gx, gy, ax, ay, x, gy - y));
92            }
93        }
94        Ok(g)
95    }
96
97    /// Number of cells (not vertices) in x.
98    pub fn gx(&self) -> u32 {
99        self.gx
100    }
101
102    /// Number of cells (not vertices) in y.
103    pub fn gy(&self) -> u32 {
104        self.gy
105    }
106
107    /// `m_fAspectX` (computed from the texture size).
108    pub fn aspect_x(&self) -> f32 {
109        self.aspect_x
110    }
111
112    /// `m_fAspectY` (computed from the texture size).
113    pub fn aspect_y(&self) -> f32 {
114        self.aspect_y
115    }
116
117    /// Clip-space x of each vertex (`m_verts[n].x`).
118    pub fn x(&self) -> &[f32] {
119        &self.x
120    }
121
122    /// Clip-space y of each vertex (`m_verts[n].y`).
123    pub fn y(&self) -> &[f32] {
124        &self.y
125    }
126
127    /// `m_vertinfo[n].rad` of each vertex.
128    pub fn rad(&self) -> &[f32] {
129        &self.rad
130    }
131
132    /// `m_vertinfo[n].ang` of each vertex (-pi..pi as `atan2f`, centre vertex 0).
133    pub fn ang(&self) -> &[f32] {
134        &self.ang
135    }
136
137    /// Number of vertices, `(gx + 1) * (gy + 1)`.
138    pub fn vertex_count(&self) -> usize {
139        ((self.gx + 1) * (self.gy + 1)) as usize
140    }
141
142    /// Index of the vertex at column `x`, row `y` (row 0 = bottom of the screen).
143    #[inline]
144    pub fn index(&self, x: u32, y: u32) -> usize {
145        (y * (self.gx + 1) + x) as usize
146    }
147
148    /// Preset-space `x` (0 = left .. 1 = right) of vertex `n`, as per-pixel code sees it:
149    /// `m_verts[n].x*0.5*aspectX + 0.5`.
150    pub fn pv_x(&self, n: usize) -> f32 {
151        self.x[n] * 0.5 * self.aspect_x + 0.5
152    }
153    /// Preset-space `y` (0 = top .. 1 = bottom): `m_verts[n].y*-0.5*aspectY + 0.5`.
154    pub fn pv_y(&self, n: usize) -> f32 {
155        self.y[n] * -0.5 * self.aspect_y + 0.5
156    }
157
158    /// projectM's own vertex data (`PerPixelMesh::InitializeMesh`) for the vertex at column `x`, lactea
159    /// row `y` (row 0 = bottom). projectM's mesh row 0 is the *top* of the image, so its `y` is
160    /// `row_pm / gy * 2 - 1` with `row_pm = gy - y` (float rounding differs from `-self.y[n]`);
161    /// `rad = hypotf(x*ax, y*ay)`, `ang = atan2f(y*ay, x*ax)` (0 at the centre vertex).
162    /// Returns `(pos, rad, ang)`.
163    #[inline]
164    pub fn projectm_vertex(&self, x: u32, y: u32) -> ([f32; 2], f32, f32) {
165        if x <= self.gx && y <= self.gy {
166            self.pm[self.index(x, y)]
167        } else {
168            projectm_vertex(
169                self.gx,
170                self.gy,
171                self.aspect_x,
172                self.aspect_y,
173                x,
174                self.gy.wrapping_sub(y),
175            )
176        }
177    }
178}
179
180/// The uncached formula behind [`MeshGeometry::projectm_vertex`]; `row_pm` is projectM's mesh row (0 = top).
181fn projectm_vertex(
182    gx: u32,
183    gy: u32,
184    ax: f32,
185    ay: f32,
186    x: u32,
187    row_pm: u32,
188) -> ([f32; 2], f32, f32) {
189    let vx = x as f32 / gx as f32 * 2.0 - 1.0;
190    let vy = row_pm as f32 / gy as f32 * 2.0 - 1.0;
191    let rad = (vx * ax).hypot(vy * ay);
192    let ang = if row_pm == gy / 2 && x == gx / 2 {
193        0.0
194    } else {
195        (vy * ay).atan2(vx * ax)
196    };
197    ([vx, vy], rad, ang)
198}
199
200/// The ten per-vertex motion variables after (optional) per-pixel code
201/// (`pv_zoom, pv_zoomexp, pv_rot, pv_warp, pv_cx, pv_cy, pv_dx, pv_dy, pv_sx, pv_sy`).
202#[derive(Clone, Copy, Debug, PartialEq)]
203pub struct VertexVars {
204    /// `pv_zoom`
205    pub zoom: f32,
206    /// `pv_zoomexp`
207    pub zoomexp: f32,
208    /// `pv_rot`
209    pub rot: f32,
210    /// `pv_warp`
211    pub warp: f32,
212    /// `pv_cx`
213    pub cx: f32,
214    /// `pv_cy`
215    pub cy: f32,
216    /// `pv_dx`
217    pub dx: f32,
218    /// `pv_dy`
219    pub dy: f32,
220    /// `pv_sx`
221    pub sx: f32,
222    /// `pv_sy`
223    pub sy: f32,
224}
225
226impl Default for VertexVars {
227    /// MD2 defaults (state.cpp `Default`): identity motion.
228    fn default() -> Self {
229        Self {
230            zoom: 1.0,
231            zoomexp: 1.0,
232            rot: 0.0,
233            warp: 1.0,
234            cx: 0.5,
235            cy: 0.5,
236            dx: 0.0,
237            dy: 0.0,
238            sx: 1.0,
239            sy: 1.0,
240        }
241    }
242}
243
244/// Warp-animation terms computed once per frame in `ComputeGridAlphaValues`.
245#[derive(Clone, Copy, Debug, PartialEq)]
246pub struct WarpAnim {
247    /// projectM's warp vertex shader evaluates the four warp terms with a mesh `y` of the
248    /// opposite sign (its mesh row 0 is the top of the image, MD2's the bottom). `true` flips
249    /// `y` in those terms ([`WarpAnim::projectm`]).
250    pub y_flip: bool,
251    /// projectM computes `pow(zoom, ..)` in a GPU vertex shader, where a negative base gives NaN (`exp2(y*log2(x))`);
252    /// MD2 does it on the CPU (`powf`, finite). `true` in [`WarpAnim::projectm`].
253    pub gpu_pow: bool,
254    /// MilkDrop 3 adds the four warp `sin` / `cos` terms only when `|warp| > 0.0001`; MD2 always adds them
255    /// (`CompatRules::md3_warp_skip_tiny`).
256    pub skip_tiny_warp: bool,
257    /// `fWarpTime = GetTime() * m_fWarpAnimSpeed`
258    pub warp_time: f32,
259    /// `fWarpScaleInv = 1 / m_fWarpScale`
260    pub scale_inv: f32,
261    /// `f[0..4]`
262    pub f: [f32; 4],
263}
264
265impl WarpAnim {
266    /// `time` = `GetTime()`, `warp_anim_speed` = preset `fWarpAnimSpeed`, `warp_scale` = `fWarpScale`.
267    pub fn new(time: f32, warp_anim_speed: f32, warp_scale: f32) -> Self {
268        let warp_time = time * warp_anim_speed;
269        let f = [
270            11.68 + 4.0 * (warp_time * 1.413 + 10.0).cos(),
271            8.77 + 3.0 * (warp_time * 1.113 + 7.0).cos(),
272            10.54 + 3.0 * (warp_time * 1.233 + 3.0).cos(),
273            11.49 + 4.0 * (warp_time * 0.933 + 5.0).cos(),
274        ];
275        Self {
276            y_flip: false,
277            gpu_pow: false,
278            skip_tiny_warp: false,
279            warp_time,
280            scale_inv: 1.0 / warp_scale,
281            f,
282        }
283    }
284
285    /// Like [`WarpAnim::new`] with projectM's `y` convention in the warp terms.
286    pub fn projectm(time: f32, warp_anim_speed: f32, warp_scale: f32) -> Self {
287        Self {
288            y_flip: true,
289            gpu_pow: true,
290            ..Self::new(time, warp_anim_speed, warp_scale)
291        }
292    }
293}
294
295/// MD2's per-vertex UV (the non-blending branch of `ComputeGridAlphaValues`).
296///
297/// `texel_offset_uv` = `texel_offset / texsize` (MD2: `0.5 / m_nTexSizeX`); added last.
298/// Returns `(tu, tv)`.
299pub fn warp_vertex_uv(
300    g: &MeshGeometry,
301    n: usize,
302    v: &VertexVars,
303    anim: &WarpAnim,
304    texel_offset_uv: [f32; 2],
305) -> [f32; 2] {
306    let vx = g.x[n];
307    let vy = g.y[n];
308    // `y` as the warp terms see it (see `WarpAnim::y_flip`)
309    let wy = if anim.y_flip { -vy } else { vy };
310    let rad = g.rad[n];
311    let f = &anim.f;
312
313    let zoom2 = if anim.gpu_pow && v.zoom < 0.0 {
314        f32::NAN
315    } else {
316        v.zoom.powf(v.zoomexp.powf(rad * 2.0 - 1.0))
317    };
318    let zoom2_inv = 1.0 / zoom2;
319
320    let mut u = vx * g.aspect_x * 0.5 * zoom2_inv + 0.5;
321    let mut vv = -vy * g.aspect_y * 0.5 * zoom2_inv + 0.5;
322
323    // stretch on X, Y
324    u = (u - v.cx) / v.sx + v.cx;
325    vv = (vv - v.cy) / v.sy + v.cy;
326
327    // warping
328    let wt = anim.warp_time;
329    let si = anim.scale_inv;
330    if !anim.skip_tiny_warp || v.warp.abs() > 0.0001 {
331        u += v.warp * 0.0035 * (wt * 0.333 + si * (vx * f[0] - wy * f[3])).sin();
332        vv += v.warp * 0.0035 * (wt * 0.375 - si * (vx * f[2] + wy * f[1])).cos();
333        u += v.warp * 0.0035 * (wt * 0.753 - si * (vx * f[1] - wy * f[2])).cos();
334        vv += v.warp * 0.0035 * (wt * 0.825 + si * (vx * f[0] + wy * f[3])).sin();
335    }
336
337    // rotation
338    let u2 = u - v.cx;
339    let v2 = vv - v.cy;
340    let cos_rot = v.rot.cos();
341    let sin_rot = v.rot.sin();
342    u = u2 * cos_rot - v2 * sin_rot + v.cx;
343    vv = u2 * sin_rot + v2 * cos_rot + v.cy;
344
345    // translation
346    u -= v.dx;
347    vv -= v.dy;
348
349    // undo aspect ratio fix
350    u = (u - 0.5) * (1.0 / g.aspect_x) + 0.5;
351    vv = (vv - 0.5) * (1.0 / g.aspect_y) + 0.5;
352
353    // final texel-offset translation
354    u += texel_offset_uv[0];
355    vv += texel_offset_uv[1];
356    [u, vv]
357}
358
359/// The default per-vertex path (no per-pixel code): every vertex uses the same frame variables.
360pub fn warp_mesh_uniform(
361    g: &MeshGeometry,
362    v: &VertexVars,
363    anim: &WarpAnim,
364    texel_offset_uv: [f32; 2],
365) -> Vec<[f32; 2]> {
366    (0..g.vertex_count())
367        .map(|n| warp_vertex_uv(g, n, v, anim, texel_offset_uv))
368        .collect()
369}
370
371/// `texel_offset` (texels) -> UV offset for a texture size, as `RenderConfig` defines it.
372pub fn texel_offset_uv(texel_offset: [f32; 2], tex_w: u32, tex_h: u32) -> [f32; 2] {
373    [
374        texel_offset[0] / tex_w as f32,
375        texel_offset[1] / tex_h as f32,
376    ]
377}
378
379#[cfg(test)]
380mod tests {
381    use super::*;
382
383    fn close(a: f32, b: f32) -> bool {
384        (a - b).abs() < 1e-5
385    }
386
387    #[test]
388    fn geometry_matches_md2_setup() {
389        let g = MeshGeometry::new(48, 36, 640, 360).unwrap();
390        assert_eq!(g.vertex_count(), 49 * 37);
391        assert!(close(g.aspect_x, 1.0));
392        assert!(close(g.aspect_y, 360.0 / 640.0));
393        // row 0 = clip y -1, x runs -1..1
394        assert!(close(g.x[0], -1.0) && close(g.y[0], -1.0));
395        assert!(close(g.x[48], 1.0) && close(g.y[48], -1.0));
396        let last = g.vertex_count() - 1;
397        assert!(close(g.x[last], 1.0) && close(g.y[last], 1.0));
398        // center vertex: rad 0, ang forced to 0
399        let c = g.index(24, 18);
400        assert!(close(g.rad[c], 0.0) && g.ang[c] == 0.0);
401        // corner rad = sqrt(ax^2 + ay^2)
402        let corner = (1.0f32 + (360.0f32 / 640.0).powi(2)).sqrt();
403        assert!(close(g.rad[0], corner));
404        // preset-space coords: row 0 is the *bottom* (pv_y = 1)
405        assert!(close(g.pv_y(0), 0.5 + 0.5 * g.aspect_y));
406        assert!(close(g.pv_x(0), 0.0));
407    }
408
409    #[test]
410    fn identity_motion_maps_to_screen_uv() {
411        // zoom=1, rot=0, warp=0, no translation: uv must equal the screen position (v=0 at top)
412        let g = MeshGeometry::new(48, 36, 640, 360).unwrap();
413        let anim = WarpAnim::new(3.0, 1.0, 1.0);
414        let v = VertexVars {
415            warp: 0.0,
416            ..Default::default()
417        };
418        let uv = warp_mesh_uniform(&g, &v, &anim, [0.0, 0.0]);
419        for n in 0..g.vertex_count() {
420            assert!(close(uv[n][0], g.x[n] * 0.5 + 0.5), "u {n}");
421            assert!(close(uv[n][1], -g.y[n] * 0.5 + 0.5), "v {n}");
422        }
423        // row 0 (bottom of screen) samples v = 1
424        assert!(close(uv[0][1], 1.0));
425    }
426
427    #[test]
428    fn zoom_rot_translate_hand_computed() {
429        let g = MeshGeometry::new(2, 2, 100, 100).unwrap(); // aspect 1,1; vertices at -1,0,1
430        let anim = WarpAnim::new(0.0, 1.0, 1.0);
431        // zoom 2 (zoomexp 1 -> constant), pure zoom: u = x*0.5/2 + 0.5
432        let v = VertexVars {
433            zoom: 2.0,
434            warp: 0.0,
435            ..Default::default()
436        };
437        let uv = warp_vertex_uv(&g, g.index(2, 0), &v, &anim, [0.0, 0.0]); // x=1,y=-1
438        assert!(close(uv[0], 0.75) && close(uv[1], 0.75));
439        // rotation by pi/2 about (0.5,0.5): vertex x=1,y=1 (screen u=1,v=0): (u2,v2)=(0.5,-0.5)
440        // -> (u2*0 - v2*1, u2*1 + v2*0) = (0.5, 0.5) -> (1.0, 1.0)
441        let v = VertexVars {
442            rot: std::f32::consts::FRAC_PI_2,
443            warp: 0.0,
444            ..Default::default()
445        };
446        let uv = warp_vertex_uv(&g, g.index(2, 2), &v, &anim, [0.0, 0.0]);
447        assert!(close(uv[0], 1.0) && close(uv[1], 1.0));
448        // translation + texel offset
449        let v = VertexVars {
450            dx: 0.1,
451            dy: -0.2,
452            warp: 0.0,
453            ..Default::default()
454        };
455        let uv = warp_vertex_uv(&g, g.index(1, 1), &v, &anim, [0.001, 0.002]);
456        assert!(close(uv[0], 0.5 - 0.1 + 0.001) && close(uv[1], 0.5 + 0.2 + 0.002));
457    }
458
459    #[test]
460    fn warp_terms_are_applied() {
461        let g = MeshGeometry::new(4, 4, 64, 64).unwrap();
462        let anim = WarpAnim::new(1.0, 1.0, 1.0);
463        assert!(close(anim.f[0], 11.68 + 4.0 * (1.413f32 + 10.0).cos()));
464        let a = warp_vertex_uv(
465            &g,
466            7,
467            &VertexVars {
468                warp: 0.0,
469                ..Default::default()
470            },
471            &anim,
472            [0.0; 2],
473        );
474        let b = warp_vertex_uv(
475            &g,
476            7,
477            &VertexVars {
478                warp: 1.0,
479                ..Default::default()
480            },
481            &anim,
482            [0.0; 2],
483        );
484        let (du, dv) = ((b[0] - a[0]).abs(), (b[1] - a[1]).abs());
485        assert!(
486            du > 0.0 && du < 0.0141 && dv < 0.0141,
487            "warp displacement bounded by 2*0.0035: {du} {dv}"
488        );
489    }
490
491    /// MilkDrop 3: the four warp terms are added only when `|warp| > 0.0001` (T4: 0.0001 skips, 0.0002 adds
492    /// them with the factor `0.0002 * 0.0035`); MD2 adds them for any warp.
493    #[test]
494    fn tiny_warp_skips_the_terms_under_md3() {
495        let g = MeshGeometry::new(4, 4, 64, 64).unwrap();
496        let md2 = WarpAnim::new(1.0, 1.0, 1.0);
497        let md3 = WarpAnim {
498            skip_tiny_warp: true,
499            ..md2
500        };
501        let uv = |warp: f32, anim: &WarpAnim| {
502            warp_vertex_uv(
503                &g,
504                7,
505                &VertexVars {
506                    warp,
507                    ..Default::default()
508                },
509                anim,
510                [0.0; 2],
511            )
512        };
513        let base = uv(0.0, &md3);
514        assert_eq!(uv(0.0001, &md3), base, "|warp| <= 1e-4: skipped");
515        assert_eq!(uv(-0.0001, &md3), base);
516        assert_ne!(uv(0.0001, &md2), base, "MD2 adds the terms");
517        let big = uv(0.0002, &md3);
518        assert_eq!(big, uv(0.0002, &md2), "above the threshold both add them");
519        assert_ne!(big, base);
520        assert_eq!(uv(1.0, &md3), uv(1.0, &md2));
521    }
522
523    /// `projectm_vertex` is projectM's `InitializeMesh` row for the mirrored mesh row: row 0 (bottom) is
524    /// projectM's last row (`y = +1`), the centre vertex has `ang = 0`, and the float rounding is projectM's
525    /// (`y = row_pm/gy*2-1`, e.g. row 34 of 36 is 0.8888889 where `-(2/36*2-1)` is not bit-identical).
526    #[test]
527    fn projectm_vertex_follows_initialize_mesh() {
528        let g = MeshGeometry::new(48, 36, 640, 360).unwrap();
529        let (p0, rad0, _) = g.projectm_vertex(0, 0);
530        assert_eq!(p0, [-1.0, 1.0]);
531        assert!(close(rad0, (1.0f32 + (360.0f32 / 640.0).powi(2)).sqrt()));
532        let (pc, radc, angc) = g.projectm_vertex(24, 18);
533        assert_eq!((pc, radc, angc), ([0.0, 0.0], 0.0, 0.0));
534        // mesh row 2 of projectM (top) is lactea row 34; its y is exactly 2/36*2-1
535        let (p, rad, ang) = g.projectm_vertex(24, 34);
536        assert_eq!(p[1], 2.0f32 / 36.0 * 2.0 - 1.0);
537        assert_eq!(rad, (p[1] * g.aspect_y).abs());
538        assert!(ang < 0.0, "top half has negative atan2(y, x)");
539        // centre row, left half: atan2f(+0, -x) = +pi
540        assert_eq!(g.projectm_vertex(3, 18).2, std::f32::consts::PI);
541    }
542
543    #[test]
544    fn negative_zoom_is_nan_on_the_gpu_but_finite_in_md2() {
545        let g = MeshGeometry::new(4, 4, 64, 64).unwrap();
546        let v = VertexVars {
547            zoom: -0.5,
548            ..Default::default()
549        };
550        let uv = warp_vertex_uv(&g, 7, &v, &WarpAnim::projectm(1.0, 1.0, 1.0), [0.0; 2]);
551        assert!(uv[0].is_nan() && uv[1].is_nan());
552        let uv = warp_vertex_uv(&g, 7, &v, &WarpAnim::new(1.0, 1.0, 1.0), [0.0; 2]);
553        assert!(uv[0].is_finite() && uv[1].is_finite());
554        // positive zoom is unaffected
555        let v = VertexVars {
556            zoom: 1.5,
557            ..Default::default()
558        };
559        let uv = warp_vertex_uv(&g, 7, &v, &WarpAnim::projectm(1.0, 1.0, 1.0), [0.0; 2]);
560        assert!(uv[0].is_finite() && uv[1].is_finite());
561    }
562}