Add loader to lib

This commit is contained in:
DefectingCat
2022-10-18 16:26:17 +08:00
parent 5a1b95bd7c
commit dcd6b7ea6a
3 changed files with 17 additions and 19 deletions

12
lib/gltfLoader.ts Normal file
View File

@ -0,0 +1,12 @@
import { THREE } from 'rua-three';
import { DRACOLoader } from 'three/examples/jsm/loaders/DRACOLoader';
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader';
const manager = new THREE.LoadingManager();
const gltfLoader = new GLTFLoader(manager);
const dracoLoader = new DRACOLoader();
dracoLoader.setDecoderPath('./libs/draco/');
dracoLoader.setDecoderConfig({ type: 'wasm' });
gltfLoader.setDRACOLoader(dracoLoader);
export { manager, gltfLoader, dracoLoader };

View File

@ -1,23 +1,16 @@
import TWEEN from '@tweenjs/tween.js';
import classNames from 'classnames';
import { gltfLoader, manager } from 'lib/gltfLoader';
import { getMousePosition } from 'lib/utils';
import { useTheme } from 'next-themes';
import dynamic from 'next/dynamic';
import { useEffect, useRef, useState } from 'react';
import { InitFn, THREE, useThree } from 'rua-three';
import { DRACOLoader } from 'three/examples/jsm/loaders/DRACOLoader';
import { GLTF, GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader';
import { GLTF } from 'three/examples/jsm/loaders/GLTFLoader';
import { NextPageWithLayout } from 'types';
const Loading = dynamic(() => import('components/RUA/loading/RUALoading'));
const manager = new THREE.LoadingManager();
const glftLoader = new GLTFLoader(manager);
const dracoLoader = new DRACOLoader();
dracoLoader.setDecoderPath('./libs/draco/');
dracoLoader.setDecoderConfig({ type: 'wasm' });
glftLoader.setDRACOLoader(dracoLoader);
const rotationY = 0.4;
const rotationX = 0.2;
@ -163,7 +156,7 @@ const About: NextPageWithLayout = () => {
});
};
glftLoader.load('./models/cloud_station/modelDraco.gltf', handleLoad);
gltfLoader.load('./models/cloud_station/modelDraco.gltf', handleLoad);
};
const { ref } = useThree({

View File

@ -1,4 +1,5 @@
import cn from 'classnames';
import { gltfLoader, manager } from 'lib/gltfLoader';
import { getMousePosition } from 'lib/utils';
import dynamic from 'next/dynamic';
import Image from 'next/future/image';
@ -6,20 +7,12 @@ import Head from 'next/head';
import { useCallback, useEffect, useRef, useState } from 'react';
import { InitFn, THREE, useThree } from 'rua-three';
import styles from 'styles/index/index.module.css';
import { DRACOLoader } from 'three/examples/jsm/loaders/DRACOLoader';
import { GLTF, GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader';
import { GLTF } from 'three/examples/jsm/loaders/GLTFLoader';
import type { NextPageWithLayout } from 'types';
const MainLayout = dynamic(() => import('layouts/MainLayout'));
const Loading = dynamic(() => import('components/RUA/loading/RUALoading'));
const manager = new THREE.LoadingManager();
const gltfLoader = new GLTFLoader(manager);
const dracoLoader = new DRACOLoader();
dracoLoader.setDecoderPath('./libs/draco/');
dracoLoader.setDecoderConfig({ type: 'wasm' });
gltfLoader.setDRACOLoader(dracoLoader);
const rotationY = 0.4;
const rotationX = 0.18;