feat(web): tint objects by their ColorDiffuse

Model ColorDiffuse in shared types and multiply each viewer's material color by the per-object tint, including textured faces and loaded custom models.
This commit is contained in:
2026-08-08 22:38:12 +08:00
parent a6e9d2dd07
commit 82a81c9c1a
7 changed files with 114 additions and 21 deletions
@@ -1,4 +1,25 @@
import * as THREE from 'three';
import type { TTSObject } from '@tts/shared';
/**
* The per-object tint (`ColorDiffuse`, 01 per channel) as a three.js color,
* defaulting to white when absent. TTS multiplies this by the object's base
* color, so textured faces are tinted too.
*/
export function objectTint(object: TTSObject): THREE.Color {
const c = object.ColorDiffuse;
return c ? new THREE.Color(c.r, c.g, c.b) : new THREE.Color(1, 1, 1);
}
/** A stable cache key fragment for a tint, so tinted variants don't collide. */
export function tintKey(color: THREE.Color): string {
return `${color.r},${color.g},${color.b}`;
}
/** Multiply a base color by the object's tint. */
export function tintedColor(base: THREE.Color, tint: THREE.Color): THREE.Color {
return base.clone().multiply(tint);
}
/**
* Module-level caches so the full-setup view can share geometry and materials