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:
@@ -1,4 +1,25 @@
|
||||
import * as THREE from 'three';
|
||||
import type { TTSObject } from '@tts/shared';
|
||||
|
||||
/**
|
||||
* The per-object tint (`ColorDiffuse`, 0–1 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
|
||||
|
||||
Reference in New Issue
Block a user