feat: faster models

This commit is contained in:
TrèsAbhi committed 2024-10-29 16:21:44 -05:00
1 parent 0f29145ab0
commit e05f02099d
8 files changed
+77 -34

No files matched your search

+11 -1
View File
@@ -2,6 +2,7 @@ import { asset } from '@blitzkit/core';
import { type ObjectMap, useLoader } from '@react-three/fiber';
import { Mesh, MeshStandardMaterial } from 'three';
import { type GLTF, GLTFLoader } from 'three-stdlib';
import { DRACOLoader } from 'three/examples/jsm/loaders/DRACOLoader';
const cache: Record<
number,
@@ -12,7 +13,16 @@ const cache: Record<
> = {};
export function useModel(id: number) {
const gltf = useLoader(GLTFLoader, asset(`3d/tanks/models/${id}.glb`));
const gltf = useLoader(
GLTFLoader,
asset(`3d/tanks/models/${id}.glb`),
(loader) => {
const dracoLoader = new DRACOLoader();
dracoLoader.setDecoderPath('https://www.gstatic.com/draco/v1/decoders/');
loader.setDRACOLoader(dracoLoader);
},
);
if (!cache[id]) {
cache[id] = {
gltf,