CodeSampleX

샘플

three 0.185.1: CanvasTexture defaults flipY to true to invert UV y-coordinates during transformUv, leaves transformUv unaffected by offset and repeat changes until updateMatrix is explicitly invoked despite matrixAutoUpdate being true, serializes metadata type as Texture, and dynamically queries width and height from its canvas source.

검증된 샘플 — npm three 0.185.1: CanvasTexture defaults flipY to true to invert UV y-coordinates during transformUv, leaves transformUv unaffected by offset and…

sha256:ccfffdc4d532f6655a078a8aec64c2e1fcba5f233b00b6548e2fc29475452d30

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. MIT-0

실행 증거

선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.

증거 기준
서명된 컨트랙트 통과
검증 영수증
3
빌드한 서명 키
3
선언된 환경 node linux x64 node node npm

검증 실행 환경

환경 컨트랙트 단계 실행일
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

케이스

HOW
목표
CanvasTexture defaults flipY to true to invert UV y-coordinates during transformUv, leaves transformUv unaffected by offset and repeat changes until updateMatrix is explicitly invoked despite matrixAutoUpdate being true, serializes metadata type as Texture, and dynamically queries width and height from its canvas source.
패키지
심벌
  • THREE.CanvasTexture
환경
node
생성일
2026-08-17T09:13:42Z

컨트랙트

  1. CanvasTexture transforms UV coordinates with flipY inversion but leaves transformUv unaffected by offset or repeat changes until updateMatrix is called manually, even when matrixAutoUpdate is true.
  2. CanvasTexture constructor applies default texture wrapping, filtering, RGBA format, and NoColorSpace while dynamically computing width and height from the underlying canvas.
  3. Calling transformUv on non-UV mappings skips matrix transformation and flipY inversion entirely.
  4. Serializing CanvasTexture with toJSON outputs metadata type Texture rather than CanvasTexture and captures wrap, filtering, and flipY settings.
  5. Setting values with setValues copies Vector2 properties and dispatches synchronous events on dispose.

파일

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

소스 아티팩트 내려받기 (tar.gz)

소스

NOTES.md
# three — CanvasTexture UV Transformation, Serialization, and Source Dimensions

## Known Solution Search
`search_known_solution` returned an existing sample `sha256:961598ac78d3b67c9b8b2e7ca83648daa11ea9e976e9ef72e5fd7dc4fdc5a4a4` which proved constructor `needsUpdate` setter semantics and version counter incrementing. This sample investigates a different set of behaviors: UV coordinate transformation and matrix updates, dynamic dimension tracking from canvas source, serialization typing, and lifecycle event dispatch.

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

## Observed Behavior
1. **UV Inversion via flipY**: `CanvasTexture` defaults `flipY` to `true`. When `transformUv(uv)` is called on a texture configured with `UVMapping`, it applies matrix multiplication and then flips the Y coordinate (`uv.y = 1 - uv.y`) so that 2D HTML canvas coordinates (top-left origin) map correctly to WebGL texture coordinates (bottom-left origin).
2. **Matrix Update Trap in transformUv**: Even though `matrixAutoUpdate` defaults to `true`, `transformUv(uv)` operates directly on `this.matrix` and does not automatically recompute the transformation matrix from `offset`, `repeat`, `rotation`, and `center`. Mutating `offset` or `repeat` has no effect on `transformUv()` until `texture.updateMatrix()` is explicitly called.
3. **Non-UV Mapping Bypass**: When `mapping` is set to any non-UV mapping mode (such as `CubeReflectionMapping`), `transformUv(uv)` returns early, skipping matrix transformation and `flipY` inversion entirely.
4. **Dynamic Canvas Dimensions**: The getters `.width` and `.height` query `this.source.getSize()`. They dynamically read `canvas.width` and `canvas.height` from the canvas data object, returning `0` when no canvas is attached, and update immediately when `texture.image` is reassigned to another canvas.
5. **Serialization as Base Texture**: Calling `.toJSON()` on a `CanvasTexture` generates serialization metadata with `type: 'Texture'` rather than `'CanvasTexture'`.
6. **Synchronous Dispose Notification**: Calling `.dispose()` dispatches a `'dispose'` event synchronously to all registered event listeners via `EventDispatcher`.

## Failure Mode
- **Silent failure on UV coordinate transforms**: Code assuming that modifying `offset` or `repeat` immediately affects `transformUv()` without calling `updateMatrix()` silently computes stale or unshifted UV positions.
- **Assertion failure on serialization**: Deserializers or type validators expecting `json.metadata.type` to identify the instance as `'CanvasTexture'` fail because the serializer outputs `'Texture'`.
csx.json
{"case":{"believed":"transformUv automatically synchronizes with texture offset and repeat when matrixAutoUpdate is enabled, and CanvasTexture serializes with metadata type CanvasTexture.","caseId":"case:sha256:9ba514c6575ea9ebb4352d78426cf08f9c75f77dd4bca4d12a9beac71a1164e3","contract":["CanvasTexture transforms UV coordinates with flipY inversion but leaves transformUv unaffected by offset or repeat changes until updateMatrix is called manually, even when matrixAutoUpdate is true.","CanvasTexture constructor applies default texture wrapping, filtering, RGBA format, and NoColorSpace while dynamically computing width and height from the underlying canvas.","Calling transformUv on non-UV mappings skips matrix transformation and flipY inversion entirely.","Serializing CanvasTexture with toJSON outputs metadata type Texture rather than CanvasTexture and captures wrap, filtering, and flipY settings.","Setting values with setValues copies Vector2 properties and dispatches synchronous events on dispose."],"goal":"CanvasTexture defaults flipY to true to invert UV y-coordinates during transformUv, leaves transformUv unaffected by offset and repeat changes until updateMatrix is explicitly invoked despite matrixAutoUpdate being true, serializes metadata type as Texture, and dynamically queries width and height from its canvas source.","kind":"HOW","packages":["pkg:npm/three@0.185.1"],"schemaVersion":1,"symbols":["THREE.CanvasTexture"]},"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":["THREE.CanvasTexture"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "npm-three-wanted-0-185-1-three-canvastexture",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "npm-three-wanted-0-185-1-three-canvastexture",
      "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-three-canvastexture",
  "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. Type identity and constructor defaults ---
const mockCanvas = { width: 512, height: 256 };
const canvasTexture = new THREE.CanvasTexture(mockCanvas);

assert.strictEqual(canvasTexture.isCanvasTexture, true, 'isCanvasTexture flag must be true');
assert.strictEqual(canvasTexture.isTexture, true, 'isTexture flag must be true');
assert.strictEqual(canvasTexture instanceof THREE.CanvasTexture, true, 'Must be instance of CanvasTexture');
assert.strictEqual(canvasTexture instanceof THREE.Texture, true, 'Must be instance of Texture');

// Default properties
assert.strictEqual(canvasTexture.mapping, THREE.UVMapping, 'Default mapping must be UVMapping (300)');
assert.strictEqual(canvasTexture.wrapS, THREE.ClampToEdgeWrapping, 'Default wrapS must be ClampToEdgeWrapping (1001)');
assert.strictEqual(canvasTexture.wrapT, THREE.ClampToEdgeWrapping, 'Default wrapT must be ClampToEdgeWrapping (1001)');
assert.strictEqual(canvasTexture.magFilter, THREE.LinearFilter, 'Default magFilter must be LinearFilter (1006)');
assert.strictEqual(canvasTexture.minFilter, THREE.LinearMipmapLinearFilter, 'Default minFilter must be LinearMipmapLinearFilter (1008)');
assert.strictEqual(canvasTexture.format, THREE.RGBAFormat, 'Default format must be RGBAFormat (1023)');
assert.strictEqual(canvasTexture.type, THREE.UnsignedByteType, 'Default type must be UnsignedByteType (1009)');
assert.strictEqual(canvasTexture.anisotropy, 1, 'Default anisotropy must be 1');
assert.strictEqual(canvasTexture.colorSpace, THREE.NoColorSpace, 'Default colorSpace must be NoColorSpace ("")');
assert.strictEqual(canvasTexture.flipY, true, 'Default flipY must be true for canvas textures');
assert.strictEqual(canvasTexture.generateMipmaps, true, 'Default generateMipmaps must be true');
assert.strictEqual(canvasTexture.premultiplyAlpha, false, 'Default premultiplyAlpha must be false');
assert.strictEqual(canvasTexture.unpackAlignment, 4, 'Default unpackAlignment must be 4');
assert.strictEqual(canvasTexture.matrixAutoUpdate, true, 'Default matrixAutoUpdate must be true');

// --- 2. Dynamic dimension tracking from canvas source ---
assert.strictEqual(canvasTexture.width, 512, 'width accessor must report underlying canvas width');
assert.strictEqual(canvasTexture.height, 256, 'height accessor must report underlying canvas height');
assert.strictEqual(canvasTexture.depth, 0, 'depth accessor must return 0 for 2D canvas texture');
assert.strictEqual(canvasTexture.image, mockCanvas, 'image getter must reference mock canvas');

// Dynamically updating canvas reference updates dimensions
const resizedCanvas = { width: 1024, height: 768 };
canvasTexture.image = resizedCanvas;
assert.strictEqual(canvasTexture.width, 1024, 'width must update when image reference changes');
assert.strictEqual(canvasTexture.height, 768, 'height must update when image reference changes');

// Texture without source data returns 0 dimensions
const emptyCanvasTexture = new THREE.CanvasTexture();
assert.strictEqual(emptyCanvasTexture.width, 0, 'width without data must be 0');
assert.strictEqual(emptyCanvasTexture.height, 0, 'height without data must be 0');
assert.strictEqual(emptyCanvasTexture.depth, 0, 'depth without data must be 0');

// --- 3. UV transformation behavior & matrixAutoUpdate trap ---
// Reset image to standard canvas
canvasTexture.image = mockCanvas;

// Initial transformUv with default identity matrix and flipY = true:
// (0.25, 0.75) -> matrix keeps (0.25, 0.75) -> flipY inverts Y: (0.25, 1 - 0.75) = (0.25, 0.25)
const uv1 = new THREE.Vector2(0.25, 0.75);
canvasTexture.transformUv(uv1);
assert.strictEqual(uv1.x, 0.25, 'transformUv x-coordinate unchanged with identity matrix');
assert.strictEqual(uv1.y, 0.25, 'transformUv y-coordinate inverted via flipY (1 - 0.75 = 0.25)');

// Trap: changing offset / repeat does NOT automatically update matrix used by transformUv
canvasTexture.offset.set(0.5, 0.5);
canvasTexture.repeat.set(2, 2);
assert.strictEqual(canvasTexture.matrixAutoUpdate, true, 'matrixAutoUpdate remains true');

const uv2 = new THREE.Vector2(0.1, 0.2);
canvasTexture.transformUv(uv2);
// Because matrix was not rebuilt, transformUv still uses initial identity matrix:
assert.strictEqual(uv2.x, 0.1, 'transformUv x remains unchanged before updateMatrix() is called');
assert.strictEqual(uv2.y, 0.8, 'transformUv y reflects only flipY (1 - 0.2 = 0.8) before updateMatrix()');

// Once updateMatrix() is explicitly called, matrix is updated and transformUv applies offset, repeat, wrapping, and flipY:
canvasTexture.updateMatrix();

// Custom wrapping with RepeatWrapping
canvasTexture.wrapS = THREE.RepeatWrapping;
canvasTexture.wrapT = THREE.RepeatWrapping;

// Point (0.1, 0.2) with repeat (2,2) and offset (0.5, 0.5):
// x' = 0.1 * 2 + 0.5 = 0.7 -> RepeatWrapping keeps 0.7
// y' = 0.2 * 2 + 0.5 = 0.9 -> RepeatWrapping keeps 0.9 -> flipY: 1 - 0.9 = 0.1
const uv3 = new THREE.Vector2(0.1, 0.2);
canvasTexture.transformUv(uv3);
assert.ok(Math.abs(uv3.x - 0.7) < 1e-6, `Expected x to be 0.7, got ${uv3.x}`);
assert.ok(Math.abs(uv3.y - 0.1) < 1e-6, `Expected y to be 0.1, got ${uv3.y}`);

// Non-UV mapping bypasses transformUv entirely
const cubeTexture = new THREE.CanvasTexture(mockCanvas, THREE.CubeReflectionMapping);
const uvCube = new THREE.Vector2(0.3, 0.8);
cubeTexture.transformUv(uvCube);
assert.strictEqual(uvCube.x, 0.3, 'Non-UV mapping leaves uv.x unchanged');
assert.strictEqual(uvCube.y, 0.8, 'Non-UV mapping leaves uv.y unchanged (no flipY applied)');

// --- 4. setValues and updateRanges ---
canvasTexture.setValues({
  wrapS: THREE.MirroredRepeatWrapping,
  wrapT: THREE.ClampToEdgeWrapping,
  flipY: false,
  repeat: new THREE.Vector2(3, 4),
  offset: new THREE.Vector2(0.1, 0.2)
});
assert.strictEqual(canvasTexture.wrapS, THREE.MirroredRepeatWrapping, 'wrapS updated via setValues');
assert.strictEqual(canvasTexture.wrapT, THREE.ClampToEdgeWrapping, 'wrapT updated via setValues');
assert.strictEqual(canvasTexture.flipY, false, 'flipY updated via setValues');
assert.strictEqual(canvasTexture.repeat.x, 3, 'repeat.x copied via setValues');
assert.strictEqual(canvasTexture.repeat.y, 4, 'repeat.y copied via setValues');
assert.strictEqual(canvasTexture.offset.x, 0.1, 'offset.x copied via setValues');
assert.strictEqual(canvasTexture.offset.y, 0.2, 'offset.y copied via setValues');

// Update ranges management
canvasTexture.addUpdateRange(0, 128);
canvasTexture.addUpdateRange(256, 64);
assert.strictEqual(canvasTexture.updateRanges.length, 2, 'updateRanges contains 2 entries');
assert.deepStrictEqual(canvasTexture.updateRanges[0], { start: 0, count: 128 }, 'First update range preserved');
assert.deepStrictEqual(canvasTexture.updateRanges[1], { start: 256, count: 64 }, 'Second update range preserved');
canvasTexture.clearUpdateRanges();
assert.strictEqual(canvasTexture.updateRanges.length, 0, 'clearUpdateRanges clears array');

// --- 5. JSON serialization structure ---
const serialized = canvasTexture.toJSON();
assert.strictEqual(serialized.metadata.type, 'Texture', 'Serialized metadata.type must be "Texture"');
assert.strictEqual(serialized.metadata.version, 4.7, 'Serialized metadata.version must be 4.7');
assert.strictEqual(serialized.uuid, canvasTexture.uuid, 'Serialized uuid must match texture uuid');
assert.deepStrictEqual(serialized.wrap, [THREE.MirroredRepeatWrapping, THREE.ClampToEdgeWrapping], 'Serialized wrap must match wrapS and wrapT');
assert.deepStrictEqual(serialized.repeat, [3, 4], 'Serialized repeat array matches repeat Vector2');
assert.deepStrictEqual(serialized.offset, [0.1, 0.2], 'Serialized offset array matches offset Vector2');
assert.strictEqual(serialized.flipY, false, 'Serialized flipY matches property');
assert.strictEqual(serialized.generateMipmaps, true, 'Serialized generateMipmaps matches property');

// --- 6. Event dispatch on disposal ---
let disposeFired = false;
let disposeEventTarget = null;
const disposeListener = (event) => {
  disposeFired = true;
  disposeEventTarget = event.target;
};

canvasTexture.addEventListener('dispose', disposeListener);
canvasTexture.dispose();
assert.strictEqual(disposeFired, true, 'dispose event must fire synchronously upon calling .dispose()');
assert.strictEqual(disposeEventTarget, canvasTexture, 'dispose event target must be canvasTexture instance');

오리진 시더

csx-seed