Hey Guys,
I’m loading a GLB file in my react project. The file loads up, however there are no colors.
If I load the same file in vanilla js, it loads up with all the colors.
Note: The glb file looks proper in Blender and sandbox.babylonjs.com. However if I open the same GLB in gltf-viewer.donmccurdy.com it doesn’t show any colors.
Below is the code for my react component. I’m not sure if it’s an issue with the code or the GLB file.
Here is the link to the GLB file: city.glb - Google Drive
import React from "react";
import { Canvas } from "@react-three/fiber";
import { OrbitControls, useGLTF } from "@react-three/drei";
import * as THREE from "three";
// This component handles the loading and displaying of your GLB model
function WorldModel({ path }) {
const { nodes, materials, scene } = useGLTF(path);
return <primitive object={scene} />;
// tried nodes.Scene but the scene still looks greyscale
// return <primitive object={nodes.Scene} />;
// tried passing materials to the primitive but the scene still looks greyscale
// return <primitive object={scene} material={materials} />;
}
function World() {
return (
<div style={{ height: "100vh" }}>
<Canvas gl={{ antialias: true, toneMapping: THREE.NoToneMapping }} linear>
<ambientLight intensity={1} />
<directionalLight position={[0, 10, 5]} intensity={1} />
<WorldModel path="/models/city.glb" />
<OrbitControls />
</Canvas>
</div>
);
}
export default World;
useGLTF.preload("/models/city.glb");
Below is the vanilla js code
import * as THREE from "three";
import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader.js";
const loader = new GLTFLoader();
const container = document.createElement("div");
document.body.appendChild(container);
const scene = new THREE.Scene();
const renderer = new THREE.WebGLRenderer();
container.appendChild(renderer.domElement);
const camera = new THREE.PerspectiveCamera(35, window.innerWidth / window.innerHeight, 1, 100);
camera.position.set(34, 16, -20);
scene.add(camera);
loader.load("models/gltf/city.glb", function (gltf) {
scene.add(gltf.scene);
});
function rendeLoop() {
renderer.render(scene, camera); // render the scene using the camera
requestAnimationFrame(rendeLoop); //loop the render function
}
rendeLoop(); //start rendering