Hey guys,
I am attempting to load a glb model into a react (next js with TypeScript) application and display it. When I preview the 3d model in an online viewer I get this:
All seems fine. When I attempt to load the model in my app, it either seems to be misshapen, or its missing meshes. Here are some examples, the first one was my first attempt, the second I tried adjusting some things in the code and it went worse…
To load my model in, I first converted my GLB to a TSX using this tool.
The output looks like this:
import * as THREE from "three";
import React, { useRef } from "react";
import { useGLTF, useAnimations } from "@react-three/drei";
import { GLTF } from "three/examples/jsm/loaders/GLTFLoader";
type GLTFResult = GLTF & {
nodes: {
Door_Right: THREE.Mesh;
Cube006_1: THREE.Mesh;
Cube007_1: THREE.Mesh;
Door_Left: THREE.Mesh;
Cube012: THREE.Mesh;
Cube023: THREE.Mesh;
Beam_Top: THREE.Mesh;
Wood_beams: THREE.Mesh;
Wood_beams001: THREE.Mesh;
Cube001: THREE.Mesh;
Cylinder_1: THREE.Mesh;
Cube002: THREE.Mesh;
Cube003: THREE.Mesh;
Cube004: THREE.Mesh;
Cube005: THREE.Mesh;
Cube008: THREE.Mesh;
Cube009: THREE.Mesh;
Cube010: THREE.Mesh;
Cube011: THREE.Mesh;
Cylinder001_1: THREE.Mesh;
Cube014: THREE.Mesh;
Cube013: THREE.Mesh;
Cylinder002: THREE.Mesh;
Cube017: THREE.Mesh;
Cube016: THREE.Mesh;
Cube015: THREE.Mesh;
Cube022: THREE.Mesh;
Cube021: THREE.Mesh;
Cube020: THREE.Mesh;
Cube019: THREE.Mesh;
Cube018: THREE.Mesh;
Cylinder003: THREE.Mesh;
};
materials: {
Wood: THREE.MeshStandardMaterial;
Rust: THREE.MeshStandardMaterial;
["Rust.001"]: THREE.MeshStandardMaterial;
["Rust.018"]: THREE.MeshStandardMaterial;
["Rust.027"]: THREE.MeshStandardMaterial;
["Wood Dark"]: THREE.MeshStandardMaterial;
["Rust.002"]: THREE.MeshStandardMaterial;
["Rust.003"]: THREE.MeshStandardMaterial;
["Rust.004"]: THREE.MeshStandardMaterial;
["Rust.005"]: THREE.MeshStandardMaterial;
["Rust.006"]: THREE.MeshStandardMaterial;
["Rust.008"]: THREE.MeshStandardMaterial;
["Rust.007"]: THREE.MeshStandardMaterial;
["Rust.020"]: THREE.MeshStandardMaterial;
["Rust.019"]: THREE.MeshStandardMaterial;
["Rust.022"]: THREE.MeshStandardMaterial;
["Rust.021"]: THREE.MeshStandardMaterial;
["Rust.026"]: THREE.MeshStandardMaterial;
["Rust.025"]: THREE.MeshStandardMaterial;
["Rust.024"]: THREE.MeshStandardMaterial;
["Rust.023"]: THREE.MeshStandardMaterial;
};
};
type ActionName = "Door RightAction" | "Door LeftAction.001";
type GLTFActions = Record<ActionName, THREE.AnimationAction>;
export default function Model(props: {
groupProps?: JSX.IntrinsicElements["group"];
url: string;
}) {
const group = useRef<THREE.Group>();
const { nodes, materials, animations } = useGLTF(props.url) as GLTFResult;
const { actions } = useAnimations<GLTFActions>(animations, group);
useGLTF.preload(props.url);
return (
<group ref={group} {...props.groupProps} dispose={null}>
<scene>
<mesh
name="Door_Right"
castShadow
receiveShadow
geometry={nodes.Door_Right.geometry}
material={nodes.Door_Right.material}
position={[-0.46086833, 4.47411871, 1.81928372]}
rotation={[0, 0, -Math.PI / 2]}
scale={[1.7364651, 0.09472504, 1.77326417]}
>
<mesh
name="Cube006_1"
castShadow
receiveShadow
geometry={nodes.Cube006_1.geometry}
material={nodes.Cube006_1.material}
position={[0.09024856, 0.02326345, -0.17493892]}
rotation={[0.06934521, 0, 0]}
scale={[0.01108658, 0.09026723, 0.01096111]}
/>
<mesh
name="Cube007_1"
castShadow
receiveShadow
geometry={nodes.Cube007_1.geometry}
material={nodes.Cube007_1.material}
position={[1.93614078, 0.02326107, -0.17493892]}
rotation={[0.06934522, 0, 0]}
scale={[0.01108658, 0.09026723, 0.01096111]}
/>
</mesh>
<mesh
name="Door_Left"
castShadow
receiveShadow
geometry={nodes.Door_Left.geometry}
material={nodes.Door_Left.material}
position={[-0.45518765, 4.57606792, -1.83517742]}
rotation={[0, 0, -Math.PI / 2]}
scale={[1.7364651, 0.09472504, 1.77326417]}
>
<mesh
name="Cube012"
castShadow
receiveShadow
geometry={nodes.Cube012.geometry}
material={nodes.Cube012.material}
position={[-0.02068212, -0.02630043, 0.16728997]}
rotation={[3.00273455, 0.0000084, 5.8e-7]}
scale={[0.01108658, 0.09026723, 0.01096111]}
/>
<mesh
name="Cube023"
castShadow
receiveShadow
geometry={nodes.Cube023.geometry}
material={nodes.Cube023.material}
position={[1.827461, -0.02630329, 0.16728997]}
rotation={[3.00273455, 0.0000084, 5.8e-7]}
scale={[0.01108658, 0.09026723, 0.01096111]}
/>
</mesh>
<mesh
name="Beam_Top"
castShadow
receiveShadow
geometry={nodes.Beam_Top.geometry}
material={nodes.Beam_Top.material}
position={[-0.01158098, 6.29058456, -0.02521912]}
/>
<mesh
name="Wood_beams"
castShadow
receiveShadow
geometry={nodes.Wood_beams.geometry}
material={nodes.Wood_beams.material}
position={[0.00054604, 2.78375435, 2.28781462]}
/>
<mesh
name="Wood_beams001"
castShadow
receiveShadow
geometry={nodes.Wood_beams001.geometry}
material={nodes.Wood_beams001.material}
position={[0.0008597, 2.7946589, -2.35413432]}
/>
<mesh
name="Cube001"
castShadow
receiveShadow
geometry={nodes.Cube001.geometry}
material={nodes.Cube001.material}
position={[-0.41848296, 4.46486712, 2.28258157]}
rotation={[3.13361595, 0.0216759, -1.57056402]}
scale={[0.01925146, 0.0085508, 0.01925146]}
>
<mesh
name="Cylinder_1"
castShadow
receiveShadow
geometry={nodes.Cylinder_1.geometry}
material={nodes.Cylinder_1.material}
position={[0.2192241, -3.37392426, 24.05841827]}
rotation={[-3.0373978, -0.02227364, -0.48875934]}
scale={[5.26652813, 5.58293581, 2.35427046]}
/>
</mesh>
<mesh
name="Cube002"
castShadow
receiveShadow
geometry={nodes.Cube002.geometry}
material={materials["Rust.003"]}
position={[-0.43756998, 4.58257532, 1.81947076]}
rotation={[3.09011749, -0.00797728, 0.00005948]}
scale={[0.01925146, 0.0085508, 0.01925146]}
/>
<mesh
name="Cube003"
castShadow
receiveShadow
geometry={nodes.Cube003.geometry}
material={nodes.Cube003.material}
position={[-0.44218796, 4.46717644, 2.29209232]}
rotation={[3.13361595, 0.0216759, -1.57056402]}
scale={[0.01925146, 0.0085508, 0.01925146]}
/>
<mesh
name="Cube004"
castShadow
receiveShadow
geometry={nodes.Cube004.geometry}
material={materials["Rust.004"]}
position={[-0.44271237, 4.46717644, 2.15835524]}
rotation={[3.13361595, 0.0216759, -1.57056402]}
scale={[0.01925146, 0.0085508, 0.01925146]}
/>
<mesh
name="Cube005"
castShadow
receiveShadow
geometry={nodes.Cube005.geometry}
material={materials["Rust.005"]}
position={[-0.43756998, 4.34876633, 1.81947076]}
rotation={[-3.12504716, 0.00797732, -3.14153196]}
scale={[0.01925146, 0.0085508, 0.01925146]}
/>
<mesh
name="Cube008"
castShadow
receiveShadow
geometry={nodes.Cube008.geometry}
material={materials["Rust.006"]}
position={[-0.44271237, 1.26184869, 2.15835524]}
rotation={[3.13361595, 0.0216759, -1.57056402]}
scale={[0.01925146, 0.0085508, 0.01925146]}
/>
<mesh
name="Cube009"
castShadow
receiveShadow
geometry={nodes.Cube009.geometry}
material={nodes.Cube009.material}
position={[-0.44218796, 1.26184869, 2.29209232]}
rotation={[3.13361595, 0.0216759, -1.57056402]}
scale={[0.01925146, 0.0085508, 0.01925146]}
/>
<mesh
name="Cube010"
castShadow
receiveShadow
geometry={nodes.Cube010.geometry}
material={materials["Rust.007"]}
position={[-0.43756998, 1.37724757, 1.81947076]}
rotation={[3.09011749, -0.00797728, 0.00005948]}
scale={[0.01925146, 0.0085508, 0.01925146]}
/>
<mesh
name="Cube011"
castShadow
receiveShadow
geometry={nodes.Cube011.geometry}
material={nodes.Cube011.material}
position={[-0.41848296, 1.25953937, 2.28258157]}
rotation={[3.13361595, 0.0216759, -1.57056402]}
scale={[0.01925146, 0.0085508, 0.01925146]}
>
<mesh
name="Cylinder001_1"
castShadow
receiveShadow
geometry={nodes.Cylinder001_1.geometry}
material={nodes.Cylinder001_1.material}
position={[0.2192241, -3.37392807, 24.0584259]}
rotation={[-3.0373978, -0.02227364, -0.48875934]}
scale={[5.26652813, 5.58293581, 2.35427046]}
/>
</mesh>
<mesh
name="Cube014"
castShadow
receiveShadow
geometry={nodes.Cube014.geometry}
material={materials["Rust.020"]}
position={[-0.44447008, 4.34681368, -1.86382568]}
rotation={[-0.05147699, -0.00797726, 0.00005913]}
scale={[0.01925146, 0.0085508, 0.01925146]}
/>
<mesh
name="Cube013"
castShadow
receiveShadow
geometry={nodes.Cube013.geometry}
material={materials["Rust.019"]}
position={[-0.44447008, 4.58062267, -1.86382568]}
rotation={[0.01654558, 0.00797731, -3.14153201]}
scale={[0.01925146, 0.0085508, 0.01925146]}
/>
<mesh
name="Cylinder002"
castShadow
receiveShadow
geometry={nodes.Cylinder002.geometry}
material={nodes.Cylinder002.material}
position={[-0.44374391, 4.46399498, -1.86334646]}
rotation={[-Math.PI, 0, 0]}
scale={[0.04508097, 0.10747963, 0.04508097]}
/>
<mesh
name="Cube017"
castShadow
receiveShadow
geometry={nodes.Cube017.geometry}
material={nodes.Cube017.material}
position={[-0.42001459, 4.46794653, -2.34471536]}
rotation={[-0.00797977, 0.02542654, -1.57053418]}
scale={[0.01925146, 0.0085508, 0.01925146]}
/>
<mesh
name="Cube016"
castShadow
receiveShadow
geometry={nodes.Cube016.geometry}
material={nodes.Cube016.material}
position={[-0.443755, 4.46563721, -2.35413694]}
rotation={[-0.00797977, 0.02542654, -1.57053418]}
scale={[0.01925146, 0.0085508, 0.01925146]}
/>
<mesh
name="Cube015"
castShadow
receiveShadow
geometry={nodes.Cube015.geometry}
material={materials["Rust.021"]}
position={[-0.44377854, 4.46563721, -2.2203989]}
rotation={[-0.00797977, 0.02542654, -1.57053418]}
scale={[0.01925146, 0.0085508, 0.01925146]}
/>
<mesh
name="Cube022"
castShadow
receiveShadow
geometry={nodes.Cube022.geometry}
material={materials["Rust.026"]}
position={[-0.44447008, 1.37138617, -1.86382568]}
rotation={[0.01654558, 0.00797731, -3.14153201]}
scale={[0.01925146, 0.0085508, 0.01925146]}
/>
<mesh
name="Cube021"
castShadow
receiveShadow
geometry={nodes.Cube021.geometry}
material={materials["Rust.025"]}
position={[-0.44447008, 1.13757718, -1.86382568]}
rotation={[-0.05147699, -0.00797726, 0.00005913]}
scale={[0.01925146, 0.0085508, 0.01925146]}
/>
<mesh
name="Cube020"
castShadow
receiveShadow
geometry={nodes.Cube020.geometry}
material={materials["Rust.024"]}
position={[-0.44377854, 1.2564007, -2.2203989]}
rotation={[-0.00797977, 0.02542654, -1.57053418]}
scale={[0.01925146, 0.0085508, 0.01925146]}
/>
<mesh
name="Cube019"
castShadow
receiveShadow
geometry={nodes.Cube019.geometry}
material={nodes.Cube019.material}
position={[-0.443755, 1.2564007, -2.35413694]}
rotation={[-0.00797977, 0.02542654, -1.57053418]}
scale={[0.01925146, 0.0085508, 0.01925146]}
/>
<mesh
name="Cube018"
castShadow
receiveShadow
geometry={nodes.Cube018.geometry}
material={nodes.Cube018.material}
position={[-0.42001459, 1.25871003, -2.34471536]}
rotation={[-0.00797977, 0.02542654, -1.57053418]}
scale={[0.01925146, 0.0085508, 0.01925146]}
/>
<mesh
name="Cylinder003"
castShadow
receiveShadow
geometry={nodes.Cylinder003.geometry}
material={nodes.Cylinder003.material}
position={[-0.44374391, 1.25475848, -1.86334646]}
rotation={[-Math.PI, 0, 0]}
scale={[0.04508097, 0.10747963, 0.04508097]}
/>
</scene>
</group>
);
}
Once this model was in a tsx file I load it as so from index.tsx as <Model url="...">
:
<Canvas className="mt-20">
<pointLight position={[10, 10, 10]} />
<ambientLight intensity={0.4} />
<Suspense fallback={null}>
<Model url="/my.glb" />
</Suspense>
</Canvas>
The glb file is placed in the public
directory of my next js project. It does seem to correctly locate the file, and there are no console errors, just never the correct shapes that make up the doors.
I’ve tried adjusting various settings, including the camera config, and the model itself, but have not made much progress in sorting it out.
If anyone has any thoughts/suggestions on to what might be happening when I load this model, please do let me know, I would appreciate it greatly! (I’m quite new to three hence my simple explanations).