mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 19:49:50 +02:00
feat: faster models
This commit is contained in:
1 parent
0f29145ab0
commit
e05f02099d
8 files changed
+77
-34
No files matched your search
@@ -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,
|
||||
|
||||
Reference in new issue
Block a user