I'm trying to use gltfjsx and I got a proble about gltf file path #1427
-
Hello // box.jsx
import * as THREE from 'three';
import React, { Suspense, useRef, useMemo } from 'react';
import { Canvas, useFrame, useLoader } from '@react-three/fiber';
import { OrbitControls, Stars, useGLTF } from '@react-three/drei';
import { Physics, usePlane, useSphere } from '@react-three/cannon';
import styled from 'styled-components';
import Duck from './public/Scene';
const MashesContainer = styled.div'
position: fixed;
left: 0;
top: 0;
z-index: -1;
width: 100%;
height: 100%;
background-color: black;
';
export default function Meshes() {
return (
<>
<MashesContainer>
<Canvas
sRGB
shadowMap
colorManagement
gl={{ alpha: false }}
camera={{ position: [0, -12, 16], fov: 60 }}>
<ambientLight color='#121212' intensity={0.1} />
<spotLight position={[10, 15, 20]} angle={0.3} />
<hemisphereLight
color='#eeeeee'
skyColor='#fffbbb'
groundColor='#f5f5f5'
intensity={0.8}
/>
<mesh position={[0, 35, 35]}></mesh>
<OrbitControls />
<Stars />
<Suspense fallback={null}>
<Duck />
</Suspense>
</Canvas>
</MashesContainer>
</>
);
} // Scene.js
import React, { useRef } from 'react';
import { useGLTF } from '@react-three/drei';
export default function Model(props) {
const group = useRef();
const { nodes, materials } = useGLTF('/scene.gltf');
return (
<group ref={group} {...props} dispose={null}>
<group rotation={[-Math.PI / 2, 0, 0]}>
<group rotation={[Math.PI / 2, 0, 0]}>
<group
position={[0, 173.29, -2.92]}
rotation={[-Math.PI / 2, 0, 0]}
scale={[0.9, 1.09, 1.02]}>
<mesh
geometry={nodes.defaultMaterial.geometry}
material={materials.material}
/>
</group>
</group>
</group>
</group>
);
}
useGLTF.preload('/scene.gltf'); then I got an error message Could not load |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 9 replies
-
I don't think |
Beta Was this translation helpful? Give feedback.
-
first step is to pack the gltf, it is wasteful otherwise: npx gltf-pipeline -i input.gltf -o output.glb --draco.compressionLevel=10 then you can use http://gltf.pmnd.rs/ or look into docs, it's always the same, glb goes into public, everything else will just work. |
Beta Was this translation helpful? Give feedback.
-
I have solve this problem🥳! if you are not use CRA but use webpack, your webpack config need to add some below code in your webpack.config.js file |
Beta Was this translation helpful? Give feedback.
-
I have the exact issue. Seems like need to modify the webpack config but since i am using CRA app may have to 'eject' or use something like craco... |
Beta Was this translation helpful? Give feedback.
I don't think
Scene.js
should be inpublic
, this could cause issues. I would move it to a component folder...