I have started learning three js few days back. i am trying to add a gltf 3d model to my webpage but the model is transparent and doesnt look solid i have tried adding lights but the issue is not getting resolved. This is the model Canon AT-1 Retro Camera - Download Free 3D model by AleixoAlonso [9de6686] - Sketchfab. (its a bit hard to see the in my screen shots)
Here’s the code:
import * as THREE from 'three'
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js'
import { OrbitControls } from 'three/addons/controls/OrbitControls.js'
const renderer = new THREE.WebGLRenderer()
renderer.setPixelRatio( window.devicePixelRatio );
renderer.physicallyCorrectLights = true;
renderer.outputEncoding = THREE.sRGBEncoding;
renderer.setSize(window.innerWidth, window.innerHeight)
document.body.appendChild(renderer.domElement)
const scene = new THREE.Scene()
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000)
camera.position.set(0, 0, 10)
scene.add(camera)
let model
const gltfLoader = new GLTFLoader()
gltfLoader.load('/steampunk-cam/scene.gltf', function(gltf){
gltf.scene.scale.set(50, 50, 50);
model = gltf.scene
console.log(gltf.scene)
scene.add(model)
},function(xhr) {
}
)
const ambientLight = new THREE.AmbientLight(0xffffff, 1)
scene.add(ambientLight)
const directionalLight = new THREE.DirectionalLight(0xffffff, 10)
directionalLight.position.set(0, 100, 100)
scene.add(directionalLight)
const controls = new OrbitControls(camera, renderer.domElement)
function animate() {
requestAnimationFrame(animate)
controls.update()
renderer.render(scene, camera)
}
animate()```