Spaces:
Sleeping
Sleeping
File size: 1,135 Bytes
1829efb | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | import { useMemo, useEffect } from 'react'
import * as THREE from 'three'
export const SHADED_COLOR = new THREE.Color(0xb8b8b8)
export interface AssetMaterials {
wireframeMaterial: THREE.MeshBasicMaterial
shadedMaterial: THREE.MeshStandardMaterial
wireframeOverlayMaterial: THREE.MeshBasicMaterial
}
export function useAssetMaterials(): AssetMaterials {
const materials = useMemo<AssetMaterials>(
() => ({
wireframeMaterial: new THREE.MeshBasicMaterial({
color: 0x000000,
wireframe: true,
toneMapped: false,
fog: false,
}),
shadedMaterial: new THREE.MeshStandardMaterial({
color: SHADED_COLOR,
roughness: 0.75,
metalness: 0,
}),
wireframeOverlayMaterial: new THREE.MeshBasicMaterial({
color: 0x000000,
wireframe: true,
toneMapped: false,
fog: false,
}),
}),
[],
)
useEffect(() => {
return () => {
materials.wireframeMaterial.dispose()
materials.shadedMaterial.dispose()
materials.wireframeOverlayMaterial.dispose()
}
}, [materials])
return materials
}
|