refactor: tighten upload and viewer contracts
This commit is contained in:
@@ -8,25 +8,7 @@ import { CanvasTexture, Mesh, TextureLoader } from 'three'
|
||||
import type { Material, Object3D, Texture } from 'three'
|
||||
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js'
|
||||
import { normalizeTextureFilename } from '@/lib/asset-naming'
|
||||
|
||||
export interface ModelStats {
|
||||
childObjects: number
|
||||
drawCalls: number
|
||||
materials: number
|
||||
meshes: number
|
||||
textures: number
|
||||
triangles: number
|
||||
}
|
||||
|
||||
export interface ModelHierarchyNode {
|
||||
children: ModelHierarchyNode[]
|
||||
id: string
|
||||
name: string
|
||||
position: [number, number, number]
|
||||
rotation: [number, number, number]
|
||||
type: string
|
||||
visible: boolean
|
||||
}
|
||||
import type { ModelHierarchyNode, ModelStats, SceneViewerProps } from '@/lib/client-types'
|
||||
|
||||
interface OpacityMapEntry {
|
||||
target: string
|
||||
@@ -113,7 +95,7 @@ function createAlphaMapTexture(texture: Texture) {
|
||||
const cachedTexture = alphaMapTextureCache.get(texture)
|
||||
if (cachedTexture) return cachedTexture
|
||||
|
||||
const image = texture.image
|
||||
const image: unknown = texture.image
|
||||
|
||||
if (!isAlphaImageSource(image)) {
|
||||
texture.flipY = false
|
||||
@@ -269,12 +251,7 @@ function Model({
|
||||
assetUrls,
|
||||
onStatsReady,
|
||||
onHierarchyReady,
|
||||
}: {
|
||||
url: string
|
||||
assetUrls: Record<string, string>
|
||||
onStatsReady: (stats: ModelStats) => void
|
||||
onHierarchyReady: (hierarchy: ModelHierarchyNode) => void
|
||||
}) {
|
||||
}: SceneViewerProps) {
|
||||
const { scene } = useLoader(GLTFLoader, url, (loader) => {
|
||||
loader.manager.setURLModifier((requestedUrl) => resolveAssetUrl(requestedUrl, assetUrls))
|
||||
})
|
||||
@@ -308,12 +285,7 @@ export default function SceneViewer({
|
||||
assetUrls,
|
||||
onStatsReady,
|
||||
onHierarchyReady,
|
||||
}: {
|
||||
url: string
|
||||
assetUrls: Record<string, string>
|
||||
onStatsReady: (stats: ModelStats) => void
|
||||
onHierarchyReady: (hierarchy: ModelHierarchyNode) => void
|
||||
}) {
|
||||
}: SceneViewerProps) {
|
||||
return (
|
||||
<Canvas dpr={[1, 2]} camera={{ fov: 50 }}>
|
||||
<Suspense fallback={null}>
|
||||
|
||||
Reference in New Issue
Block a user