Skip to content

Commit

Permalink
fix(useLoader): loosen GLTF inference check
Browse files Browse the repository at this point in the history
  • Loading branch information
CodyJasonBennett committed Nov 26, 2023
1 parent a032377 commit ee93fbb
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions packages/fiber/src/core/hooks.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as THREE from 'three'
import * as React from 'react'
import { StateSelector, EqualityChecker } from 'zustand'
import { GLTF } from 'three/examples/jsm/loaders/GLTFLoader.js'
import { suspend, preload, clear } from 'suspend-react'
import { context, RootState, RenderCallback } from './store'
import { buildGraph, ObjectMap, is, useMutableCallback, useIsomorphicLayoutEffect } from './utils'
Expand Down Expand Up @@ -114,6 +113,8 @@ function loadingFn<L extends LoaderProto<any>>(
}
}

type GLTFLike = { scene: THREE.Object3D }

/**
* Synchronously loads and caches assets with a three loader.
*
Expand All @@ -125,14 +126,14 @@ export function useLoader<T, U extends string | string[], L extends LoaderProto<
input: U,
extensions?: Extensions<L>,
onProgress?: (event: ProgressEvent<EventTarget>) => void,
): U extends any[] ? BranchingReturn<R, GLTF, GLTF & ObjectMap>[] : BranchingReturn<R, GLTF, GLTF & ObjectMap> {
): U extends any[] ? BranchingReturn<R, GLTFLike, R & ObjectMap>[] : BranchingReturn<R, GLTFLike, R & ObjectMap> {
// Use suspense to load async assets
const keys = (Array.isArray(input) ? input : [input]) as string[]
const results = suspend(loadingFn<L>(extensions, onProgress), [Proto, ...keys], { equal: is.equ })
// Return the object/s
return (Array.isArray(input) ? results : results[0]) as U extends any[]
? BranchingReturn<R, GLTF, GLTF & ObjectMap>[]
: BranchingReturn<R, GLTF, GLTF & ObjectMap>
? BranchingReturn<R, GLTFLike, R & ObjectMap>[]
: BranchingReturn<R, GLTFLike, R & ObjectMap>
}

/**
Expand Down

0 comments on commit ee93fbb

Please sign in to comment.