@vctrl/hooks
Version:
vctrl/hooks is a React hooks package designed to simplify 3D model loading and management within React applications. It's part of the vectreal-core ecosystem and is primarily used in the vctrl/viewer React component and the official website application.
52 lines (51 loc) • 1.29 kB
TypeScript
import { Object3D } from 'three';
export declare enum ModelFileTypes {
gltf = "gltf",
glb = "glb",
usdz = "usdz"
}
export type InputFileOrDirectory = (File | FileSystemDirectoryHandle)[];
export interface ReducedGltf {
images: {
name: string;
uri: string;
}[];
buffers: {
bytelength: string;
uri: string;
}[];
}
export interface ModelFile {
model: Object3D;
type: ModelFileTypes;
name: string;
}
export interface State {
file: ModelFile | null;
isFileLoading: boolean;
progress: number;
supportedFileTypes: ModelFileTypes[];
}
export type Action = {
type: 'set-file';
payload: ModelFile;
} | {
type: 'set-file-loading';
payload: boolean;
} | {
type: 'set-progress';
payload: number;
} | {
type: 'reset-state';
};
export type EventTypes = 'multiple-models' | 'not-loaded-files' | 'load-start' | 'load-progress' | 'load-complete' | 'load-reset' | 'load-error';
export type EventData = {
'multiple-models': File[];
'not-loaded-files': File[];
'load-start': null;
'load-progress': number;
'load-complete': State['file'];
'load-reset': null;
'load-error': Error | unknown;
};
export type EventHandler<T extends EventTypes> = (data?: EventData[T]) => void;