Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/flo-bit/shapecraft. flo-bit.dev/shapecraft
Something went wrong. Try again.
1.2 kB · 36 lines
TypeScript
at main
12345678910111213141516171819202122232425262728293031323334353637import * as THREE from 'three'import type { TextureData } from '../texture/types'
export interface ToDataTextureOptions { /** * 'srgb' for color/albedo maps (default), 'linear' for data maps * (normal, roughness, AO, masks). */ colorSpace?: 'srgb' | 'linear'}
/** Convert rasterized TextureData to a repeat-wrapped THREE.DataTexture. */export function toDataTexture(tex: TextureData, options: ToDataTextureOptions = {}): THREE.DataTexture { const texture = new THREE.DataTexture( new Uint8Array(tex.data), tex.width, tex.height, THREE.RGBAFormat, THREE.UnsignedByteType, ) texture.wrapS = THREE.RepeatWrapping texture.wrapT = THREE.RepeatWrapping texture.colorSpace = options.colorSpace === 'linear' ? THREE.LinearSRGBColorSpace : THREE.SRGBColorSpace if (tex.filter === 'nearest') { // Keep texels crisp at all distances — no mips, no blending texture.magFilter = THREE.NearestFilter texture.minFilter = THREE.NearestFilter texture.generateMipmaps = false } else { texture.magFilter = THREE.LinearFilter texture.minFilter = THREE.LinearMipmapLinearFilter texture.generateMipmaps = true } texture.needsUpdate = true return texture}