CodeSampleX

Beispiel

three 0.185.1: Texture.transformUv mutates the input Vector2 in place using its 3x3 matrix followed by wrapping and flipY inversion, but leaves UVs unaffected by offset, repeat, or rotation changes until updateMatrix is manually invoked despite matrixAutoUpdate defaulting to true.

Verifiziertes Beispiel für npm three 0.185.1: Texture.transformUv mutates the input Vector2 in place using its 3x3 matrix followed by wrapping and flipY…

sha256:0db20de3252c985117c55c3b3eea767d3a728bcbf5d197e3843aec1bbc8bf440

Dieses Netzwerk bietet eine Sache: ein Sample, das baut. Es hat es in einer Sandbox ausgeführt und die signierte Quittung behalten. Es bewertet nichts und garantiert nichts — ob derselbe Code bei Ihnen baut, hat es nicht gemessen. Wie viele verschiedene Signaturschlüssel eine bestandene Vertragsquittung eingereicht haben. Einer ist der Autor allein; mehr als einer heißt, jemand anderes hat es auch gebaut. Ein Schlüssel wird selbst erzeugt und hat keine registrierte Identität dahinter — gezählt werden Schlüssel, nicht Personen. MIT-0

Ausführungsbelege

Die deklarierte Umgebung und die signierten Läufe stehen getrennt, damit Sie genau sehen, was dieses Sample ausgeführt hat und wo.

Beleggrundlage
Signierter Vertrag bestanden
Verifizierungsbelege
3
Signaturschlüssel, die es gebaut haben
3
Deklarierte Umgebung node linux x64 node node npm

Umgebungen der Verifizierungsläufe

Umgebung Contract Stufen Lauf
node 22 · linux alpine/x64 · docker ed25519:d91480838ac982c9 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1
2026-08-17
node 22 · linux alpine/x64 · docker ed25519:2175b912ea1c23b1 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1
2026-08-18
node 22 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1node:22-alpine@sha256:c610fcdfb1d5…
2026-09-07

Fall

HOW
Ziel
Texture.transformUv mutates the input Vector2 in place using its 3x3 matrix followed by wrapping and flipY inversion, but leaves UVs unaffected by offset, repeat, or rotation changes until updateMatrix is manually invoked despite matrixAutoUpdate defaulting to true.
Pakete
Symbole
  • Texture.transformUv
Umgebung
node
Erstellt
2026-08-17T09:22:51Z

Contract

  1. Texture.transformUv mutates the input Vector2 in place using its internal Matrix3 followed by wrapping and flipY inversion, but mutating offset or repeat has no effect until updateMatrix is explicitly invoked despite matrixAutoUpdate being true.
  2. Texture.transformUv applies RepeatWrapping, ClampToEdgeWrapping, and MirroredRepeatWrapping to out-of-bounds UV coordinates before applying flipY inversion.
  3. Setting texture mapping to non-UV modes like CubeReflectionMapping causes transformUv to return immediately without matrix transformation, wrapping, or flipY modification.
  4. Rotation around a configured center in Texture.updateMatrix properly transforms coordinates in accordance with the UV transform matrix.

Dateien

  • NOTES.md
  • csx.json
  • package-lock.json
  • package.json
  • test/contract.mjs

Quellartefakt herunterladen (tar.gz)

Quelltext

NOTES.md
# Three.js Texture UV Transformation (Texture.transformUv)

## Solution Cache Search
Searching the network solution cache returned sample `sha256:ccfffdc4d532f6655a078a8aec64c2e1fcba5f233b00b6548e2fc29475452d30` which focused on `CanvasTexture` inheritance, canvas dimensions, and JSON serialization. This sample investigates the core `Texture.transformUv` method directly on the pinned release.

## Pinned Release
- Package: `three`
- Version: `0.185.1` (npm)

## Observed Behavior
1. **In-Place Vector Mutation**: `Texture.prototype.transformUv(uv)` mutates the passed `Vector2` instance in place and returns the exact same instance.
2. **Matrix Update Trap**: `Texture.prototype.matrixAutoUpdate` defaults to `true`, but `transformUv(uv)` operates directly on `texture.matrix`. It does not recalculate the 3x3 transformation matrix from `offset`, `repeat`, `rotation`, or `center` on the fly. Mutating any of these properties has no effect on subsequent `transformUv` calls until `texture.updateMatrix()` is explicitly called.
3. **Coordinate Wrapping Modes**: Coordinates falling outside the `[0, 1]` range are processed according to `wrapS` and `wrapT`:
   - `RepeatWrapping` (1000): calculates `uv - Math.floor(uv)` for both positive and negative coordinate values.
   - `ClampToEdgeWrapping` (1001): clamps values `< 0` to `0` and values `> 1` to `1`.
   - `MirroredRepeatWrapping` (1002): reflects odd unit intervals (`Math.ceil(uv) - uv`) and passes through even unit intervals (`uv - Math.floor(uv)`).
4. **Sequencing with flipY**: `flipY` defaults to `true` on `Texture`. Inversion (`uv.y = 1 - uv.y`) is applied strictly after matrix multiplication and wrapping modes have completed.
5. **Non-UV Mapping Bypass**: If `texture.mapping` is set to any non-UV mapping mode (such as `CubeReflectionMapping`, `CubeRefractionMapping`, `EquirectangularReflectionMapping`, `EquirectangularRefractionMapping`, or `SphericalReflectionMapping`), `transformUv(uv)` exits immediately, leaving the input vector completely untouched.

## Failure Mode
- **Silent Incorrect UV Calculation**: Code modifying `texture.offset`, `texture.repeat`, or `texture.rotation` without explicitly invoking `texture.updateMatrix()` silently computes stale or unshifted UV coordinates without raising any runtime errors or warnings.
csx.json
{"case":{"believed":"Texture.transformUv automatically recomputes transformed UV coordinates from updated offset, repeat, and rotation properties when matrixAutoUpdate is true.","caseId":"case:sha256:02fbb904d5b4217f8493ef5d3239a84c83ff69ed520f608755f7395bed95b9bd","contract":["Texture.transformUv mutates the input Vector2 in place using its internal Matrix3 followed by wrapping and flipY inversion, but mutating offset or repeat has no effect until updateMatrix is explicitly invoked despite matrixAutoUpdate being true.","Texture.transformUv applies RepeatWrapping, ClampToEdgeWrapping, and MirroredRepeatWrapping to out-of-bounds UV coordinates before applying flipY inversion.","Setting texture mapping to non-UV modes like CubeReflectionMapping causes transformUv to return immediately without matrix transformation, wrapping, or flipY modification.","Rotation around a configured center in Texture.updateMatrix properly transforms coordinates in accordance with the UV transform matrix."],"goal":"Texture.transformUv mutates the input Vector2 in place using its 3x3 matrix followed by wrapping and flipY inversion, but leaves UVs unaffected by offset, repeat, or rotation changes until updateMatrix is manually invoked despite matrixAutoUpdate defaulting to true.","kind":"HOW","packages":["pkg:npm/three@0.185.1"],"schemaVersion":1,"symbols":["Texture.transformUv"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","ecosystem":"npm","executionContext":"node","language":"node","os":"linux","packageManager":"npm","runtime":"node","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/three@0.185.1"],"schemaVersion":1,"symbols":["Texture.transformUv"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "npm-three-wanted-0-185-1-texture-transformuv-65039bf9c9efc75a97960850",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "npm-three-wanted-0-185-1-texture-transformuv-65039bf9c9efc75a97960850",
      "version": "1.0.0",
      "dependencies": {
        "three": "0.185.1"
      }
    },
    "node_modules/three": {
      "version": "0.185.1",
      "resolved": "https://registry.npmjs.org/three/-/three-0.185.1.tgz",
      "integrity": "sha512-5aojFCXKwnjBRZvUnt3WFfEcvUJgkN5LlijRFN95hMy8WVkG4I0QNcJE+OuWvuJ0bOdStrbfXn0pkd6/QyiAlg==",
      "license": "MIT"
    }
  }
}
package.json
{
  "name": "npm-three-wanted-0-185-1-texture-transformuv-65039bf9c9efc75a97960850",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "dependencies": {
    "three": "0.185.1"
  }
}
test/contract.mjs
import assert from 'node:assert/strict';
import * as THREE from 'three';

// 1. In-place mutation and default identity transform with flipY = true
{
  const texture = new THREE.Texture();
  assert.strictEqual(texture.matrixAutoUpdate, true, 'matrixAutoUpdate defaults to true');
  assert.strictEqual(texture.flipY, true, 'flipY defaults to true on standard Texture');
  assert.strictEqual(texture.mapping, THREE.UVMapping, 'mapping defaults to UVMapping');

  const uv = new THREE.Vector2(0.3, 0.4);
  const returnedUv = texture.transformUv(uv);

  // transformUv mutates the input vector and returns the same instance
  assert.strictEqual(returnedUv, uv, 'transformUv must return the exact same mutated Vector2 instance');
  assert.strictEqual(uv.x, 0.3, 'x coordinate remains unchanged with identity matrix and [0, 1] bounds');
  assert.strictEqual(uv.y, 0.6, 'y coordinate is inverted via flipY (1 - 0.4 = 0.6)');
}

// 2. The matrixAutoUpdate trap: offset, repeat, rotation, and center changes do NOT
// automatically update the matrix used by transformUv until updateMatrix() is called
{
  const texture = new THREE.Texture();
  texture.offset.set(0.2, 0.1);
  texture.repeat.set(2.0, 3.0);

  // Before updateMatrix(), texture.matrix is still the default identity matrix
  const uvBefore = new THREE.Vector2(0.2, 0.3);
  texture.transformUv(uvBefore);
  assert.strictEqual(uvBefore.x, 0.2, 'uv.x is unchanged before updateMatrix() despite offset/repeat changes');
  assert.strictEqual(uvBefore.y, 0.7, 'uv.y is inverted to 0.7 (1 - 0.3) using stale identity matrix');

  // Once updateMatrix() is explicitly invoked, transformUv applies offset and repeat
  texture.updateMatrix();

  texture.wrapS = THREE.RepeatWrapping;
  texture.wrapT = THREE.RepeatWrapping;

  const uvAfter = new THREE.Vector2(0.2, 0.3);
  texture.transformUv(uvAfter);
  // x' = 0.2 * 2.0 + 0.2 = 0.6 -> in bounds -> 0.6
  // y' = 0.3 * 3.0 + 0.1 = 1.0 -> in bounds -> 1.0 -> flipY: 1 - 1.0 = 0.0
  assert.ok(Math.abs(uvAfter.x - 0.6) < 1e-6, `Expected x=0.6, got ${uvAfter.x}`);
  assert.ok(Math.abs(uvAfter.y - 0.0) < 1e-6, `Expected y=0.0, got ${uvAfter.y}`);
}

// 3. Coordinate wrapping modes (RepeatWrapping, ClampToEdgeWrapping, MirroredRepeatWrapping)
{
  // RepeatWrapping: wraps via uv - Math.floor(uv)
  const textureRepeat = new THREE.Texture();
  textureRepeat.flipY = false;
  textureRepeat.wrapS = THREE.RepeatWrapping;
  textureRepeat.wrapT = THREE.RepeatWrapping;

  const uvRepeat = new THREE.Vector2(2.35, -0.4);
  textureRepeat.transformUv(uvRepeat);
  assert.ok(Math.abs(uvRepeat.x - 0.35) < 1e-6, `Expected x=0.35, got ${uvRepeat.x}`);
  assert.ok(Math.abs(uvRepeat.y - 0.6) < 1e-6, `Expected y=0.6 (-0.4 - (-1)), got ${uvRepeat.y}`);

  // ClampToEdgeWrapping: clamps negative values to 0 and values > 1 to 1
  const textureClamp = new THREE.Texture();
  textureClamp.flipY = false;
  textureClamp.wrapS = THREE.ClampToEdgeWrapping;
  textureClamp.wrapT = THREE.ClampToEdgeWrapping;

  const uvClamp = new THREE.Vector2(-0.8, 1.9);
  textureClamp.transformUv(uvClamp);
  assert.strictEqual(uvClamp.x, 0, 'Negative coordinate clamped to 0');
  assert.strictEqual(uvClamp.y, 1, 'Coordinate > 1 clamped to 1');

  // MirroredRepeatWrapping: reflects odd intervals
  const textureMirror = new THREE.Texture();
  textureMirror.flipY = false;
  textureMirror.wrapS = THREE.MirroredRepeatWrapping;
  textureMirror.wrapT = THREE.MirroredRepeatWrapping;

  // Positive: floor(1.25) = 1 (odd) -> ceil(1.25) - 1.25 = 0.75
  // Positive: floor(2.25) = 2 (even) -> 2.25 - floor(2.25) = 0.25
  const uvMirrorPos = new THREE.Vector2(1.25, 2.25);
  textureMirror.transformUv(uvMirrorPos);
  assert.ok(Math.abs(uvMirrorPos.x - 0.75) < 1e-6, `Expected mirrored x=0.75, got ${uvMirrorPos.x}`);
  assert.ok(Math.abs(uvMirrorPos.y - 0.25) < 1e-6, `Expected unmirrored y=0.25, got ${uvMirrorPos.y}`);

  // Negative: floor(-0.3) = -1 (odd) -> ceil(-0.3) - (-0.3) = 0.3
  // Negative: floor(-1.3) = -2 (even) -> -1.3 - (-2) = 0.7
  const uvMirrorNeg = new THREE.Vector2(-0.3, -1.3);
  textureMirror.transformUv(uvMirrorNeg);
  assert.ok(Math.abs(uvMirrorNeg.x - 0.3) < 1e-6, `Expected mirrored negative x=0.3, got ${uvMirrorNeg.x}`);
  assert.ok(Math.abs(uvMirrorNeg.y - 0.7) < 1e-6, `Expected unmirrored negative y=0.7, got ${uvMirrorNeg.y}`);
}

// 4. Sequencing of wrapping and flipY
{
  // flipY is evaluated AFTER wrapping has completed
  const texture = new THREE.Texture();
  texture.flipY = true;
  texture.wrapS = THREE.ClampToEdgeWrapping;
  texture.wrapT = THREE.ClampToEdgeWrapping;

  const uv = new THREE.Vector2(1.5, 1.5);
  texture.transformUv(uv);
  // x is clamped to 1
  assert.strictEqual(uv.x, 1, 'x coordinate clamped to 1');
  // y is clamped to 1, then flipY produces 1 - 1 = 0
  assert.strictEqual(uv.y, 0, 'y coordinate clamped to 1 and inverted by flipY to 0');
}

// 5. Rotation around center via updateMatrix
{
  const texture = new THREE.Texture();
  texture.flipY = false;
  texture.center.set(0.5, 0.5);
  texture.rotation = Math.PI / 2;
  texture.updateMatrix();

  // (1.0, 0.5) is +0.5 along x from center (0.5, 0.5)
  // Rotating +90 degrees (pi/2) maps (1.0, 0.5) to (0.5, 0.0) in UV space
  const uv = new THREE.Vector2(1.0, 0.5);
  texture.transformUv(uv);
  assert.ok(Math.abs(uv.x - 0.5) < 1e-6, `Expected rotated x=0.5, got ${uv.x}`);
  assert.ok(Math.abs(uv.y - 0.0) < 1e-6, `Expected rotated y=0.0, got ${uv.y}`);
}

// 6. Non-UV mapping bypasses transformUv completely
{
  const nonUvMappings = [
    THREE.CubeReflectionMapping,
    THREE.CubeRefractionMapping,
    THREE.EquirectangularReflectionMapping,
    THREE.EquirectangularRefractionMapping,
    THREE.SphericalReflectionMapping
  ];

  for (const mapping of nonUvMappings) {
    const texture = new THREE.Texture();
    texture.mapping = mapping;
    texture.flipY = true;
    texture.offset.set(0.5, 0.5);
    texture.updateMatrix();

    const uv = new THREE.Vector2(0.25, 0.75);
    const result = texture.transformUv(uv);
    assert.strictEqual(result, uv, 'Returns the same vector');
    assert.strictEqual(uv.x, 0.25, 'x unchanged when mapping !== UVMapping');
    assert.strictEqual(uv.y, 0.75, 'y unchanged (no flipY, no matrix) when mapping !== UVMapping');
  }
}

Ursprungs-Seeder

csx-seed