@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.
75 lines (74 loc) • 3.53 kB
TypeScript
import { useOptimizeModel } from '../use-optimize-model';
import { ModelFileTypes, InputFileOrDirectory, ModelFile } from './types';
/**
* Custom hook to load and manage 3D models, integrating optimization functionalities.
*
* @param optimizer - Optional optimizer hook returned from useOptimizeModel.
* @returns An object containing the state, event handlers, and optimization functions.
*/
declare function useLoadModel(optimizer?: ReturnType<typeof useOptimizeModel>): {
/**
* Add an event listener to the event system.
*/
on: <T extends import('./types').EventTypes>(event: T, handler?: import('./types').EventHandler<T>) => void;
/**
* Remove an event listener from the event system.
*/
off: <T extends import('./types').EventTypes>(event: T, handler?: import('./types').EventHandler<T>) => void;
/**
* Load a model and integrate it with the optimizer if available.
* This also makes the model available in the use-model-context hook.
*/
load: (filesOrDirectories: InputFileOrDirectory) => Promise<void>;
/**
* Reset the model and optimizer state to the initial state.
*/
reset: () => void;
/**
* Integration of the optimizer
* An object containing functions to interact with the optimizer.
*
* It exposes the following functions:
*
* - `simplifyOptimization(options?: SimplifyOptions)`: Runs the simplification optimization with the given options.
* - `dedupOptimization(options?: DedupOptions)`: Runs the deduplication optimization with the given options.
* - `quantizeOptimization(options?: QuantizeOptions)`: Runs the quantization optimization with the given options.
* - `texturesCompressionOptimization(options?: TextureCompressionOptions)`: Runs the texture compression optimization with the given options.
* - `getSize()`: Returns the size of the optimized model.
* - `reset()`: Resets the optimizer.
* - `report`: The report state of the optimizer.
* - `error`: The error state of the optimizer.
* - `loading`: The loading state of the optimizer.
*/
optimize: {
simplifyOptimization: () => void;
dedupOptimization: () => void;
quantizeOptimization: () => void;
normalsOptimization: () => void;
texturesCompressOptimization: () => void;
getSize: () => void;
reset: () => void;
report: null;
error: null;
loading: boolean;
} | {
simplifyOptimization: (options?: {
ratio?: number;
error?: number;
} | undefined) => Promise<void>;
dedupOptimization: (options?: import('@gltf-transform/functions').DedupOptions | undefined) => Promise<void>;
quantizeOptimization: (options?: import('@gltf-transform/functions').QuantizeOptions | undefined) => Promise<void>;
normalsOptimization: (options?: import('@gltf-transform/functions').NormalsOptions | undefined) => Promise<void>;
texturesCompressOptimization: (options?: import('@gltf-transform/functions').TextureCompressOptions | undefined) => Promise<void>;
getSize: () => import('../use-optimize-model/types').ModelSize | null;
reset: () => void;
report: import('@gltf-transform/functions').InspectReport | null;
error: Error | null;
loading: boolean;
};
file: ModelFile | null;
isFileLoading: boolean;
progress: number;
supportedFileTypes: ModelFileTypes[];
};
export default useLoadModel;