Hi,
I’m trying to load a 3D model as a .glb file into Three.js, but I always get a black screen. I’m very new to Three.js. This is what I want to display:
Thanks. I tried it and it works perfectly, but at this moment I need just a static model without animation. There is probably a problem with lightning or camera in my code.
const camera = new THREE.PerspectiveCamera( 60, window.innerWidth / window.innerHeight, 0.001, 100000 );
camera.position.set( -100, 400, 1000 );
// konta johanna remix (CC-BY) people (license)
// https://poly.google.com/view/7PNIMdmMSPD
//loader.load( 'girl/google poly.gltf', process );
loader.load( 'https://holesa.github.io/polymodel.github.io/mountains.glb', process );
I tried to change the camera based on your code but it doesn’t work. What values do I need to set specific? I don’t know how to edit your code, because it’s too complex. Could you tell me how to change my current code?
const loader = new THREE.GLTFLoader();
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(
60,
window.innerWidth / window.innerHeight,
0.001,
100000
);
camera.position.set(-100, 400, 1000);
const renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
camera.position.z = 5;
loader.load(
"https://holesa.github.io/polymodel.github.io/mountains.glb",
function (glb) {
scene.add(glb.scene);
},
function (xhr) {
console.log((xhr.loaded / xhr.total) * 100 + "% loaded");
},
function (error) {
console.log("An error happened");
}
);
const light = new THREE.AmbientLight(0x404040); // soft white light
scene.add(light);
const animate = function () {
requestAnimationFrame(animate);
renderer.render(scene, camera);
};
animate();
When I woke up tonight, everything was so blurry too. Only the night light on the hallway was shining.
But in the morning everything was clear again. It was well lit.
You have to adjust the light, for example the position. See the full code example (code slightly modified - from the collection example with the girl) at the very top.
You can copy it and customize the three.js sources.