import React, { Component } from "react";
import * as THREE from "three";
import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader.js";
class Room extends Component {
componentDidMount() {
const loader = new GLTFLoader();
loader.load('src/assets/room.glb', function (gltf: { scene: any; }) {
const scene = new THREE.Scene();
scene.add(gltf.scene);
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
camera.position.z = 5;
const renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
function animate() {
requestAnimationFrame(animate);
renderer.render(scene, camera);
}
animate();
});
}
render() {
return <div />;
}
}
export default Room;
#new to 3js, not sure where im going wrong with rendering
46 messages · Page 1 of 1 (latest)
I would start by testing your model in an online viewer -- if you've just exported from Blender, the model itself might have issues that would be easier to solve before bringing it into your application.
i downloaded it from this website!
Also -- doesn't look like there are any lights in the scene, which most models will require. For a good default lighting setup see https://github.com/mrdoob/three.js/blob/181e04eea8b569dc09048f9dc644310ed6b745a6/examples/webgl_loader_gltf_compressed.html#L57-L63
ahh lights
Nice! All the same though, it is pretty common that downloads from websites have issues. Sketchfab is not using three.js or glTF to display that page, it has its own internal formats, and sometimes the conversion to glTF is imperfect when you download the file.
could you link an online gltf renderer?
Woaaah, it's showing so much information than https://gltf-viewer.donmccurdy.com. Super helpful
Try AmbientLight with intensity 1. Basically, lighting up everything
😢
i noticed this model has different lighting like everywhere
do i need to add more lights
Oh sad, You might need careful approach in lighting
careful approach?
Looking from this model, it seems like there is some postprocessing also going on. Bloom effect I think.
yes
I meant, you have to choose which lights to add carefully, and choose the position of the light appropriately etc...
yes
From looking at the shadows, it seems like a light is placed at open corner of the cube.
I don't know. I don't know the best approach the find the position, but I would just strategically try out the positions starting from extremes and narrow it down.
if you wanted to recreate the bloom effect, this should get pretty close:
https://threejs.org/examples/?q=bloom#webgl_postprocessing_unreal_bloom
Try with DirectionalLight and SpotLight.
very excited lemme try it out