Files
tts-workshop/apps/web/src/components/viewers/flipTexture.test.ts
T
hypercross 835250abdd feat(mesh): render cards, tiles, and tokens with separated front/back/walls
Split extrudeShapeParts into front, back, and walls so each face can carry
its own material. Flip back textures left/right on the material so they are
not mirrored, and slice card faces from the deck sprite sheet via CardID.
Resolve deck config from the parent deck, which is authoritative over a
card's own CustomDeck. Add unit tests for card resolution, sprite UVs, and
the flip helper.
2026-08-08 17:41:59 +08:00

45 lines
1.4 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import * as THREE from 'three';
import { flipTexture } from './flipTexture';
describe('flipTexture', () => {
it('negates repeat.x and shifts offset.x to keep the region in place', () => {
const tex = new THREE.Texture();
tex.repeat.set(0.5, 0.25);
tex.offset.set(0.3, 0.4);
const flipped = flipTexture(tex);
expect(flipped.repeat.x).toBeCloseTo(-0.5, 5);
expect(flipped.repeat.y).toBeCloseTo(0.25, 5);
// offset.x = 0.3 + 0.5 = 0.8; the visible region stays put while mirrored.
expect(flipped.offset.x).toBeCloseTo(0.8, 5);
expect(flipped.offset.y).toBeCloseTo(0.4, 5);
});
it('clones the source so the original is untouched', () => {
const tex = new THREE.Texture();
tex.repeat.set(1, 1);
tex.offset.set(0, 0);
const flipped = flipTexture(tex);
expect(flipped).not.toBe(tex);
expect(tex.repeat.x).toBe(1);
expect(tex.offset.x).toBe(0);
});
it('flips a sprite cell correctly', () => {
// A sprite cell: repeat 1/6, offset col/6. Flipping should mirror within
// the cell, not shift it off the sheet.
const tex = new THREE.Texture();
tex.repeat.set(1 / 6, 1 / 4);
tex.offset.set(2 / 6, 3 / 4);
const flipped = flipTexture(tex);
expect(flipped.repeat.x).toBeCloseTo(-1 / 6, 5);
expect(flipped.offset.x).toBeCloseTo(2 / 6 + 1 / 6, 5);
expect(flipped.offset.y).toBeCloseTo(3 / 4, 5);
});
});