Hello,
I’m using the following code to load GLB into LoD.
import * as THREE from 'three';
import GLTFLoader from 'three-gltf-loader';
const OrbitControls = require('three-orbitcontrols')
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
var renderer = new THREE.WebGLRenderer();
renderer.gammaOutput = true;
renderer.gammaFactor = 2.2;
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
var controls = new OrbitControls(camera, renderer.domElement);
camera.position.z = 1;
controls.update();
// Instantiate a loader
var loader = new GLTFLoader();
var lod = new THREE.LOD();
camera.position.x = 100;
camera.position.y = 100;
// Load a glTF resource
loader.load(
// resource URL
'Model.glb',
// called when the resource is loaded
function (gltf) {
gltf.scene.traverse(function (child) {
if (child.isMesh) {
var geometry = child.geometry;
var material = child.material;
var mesh = new THREE.Mesh(geometry, material);
//scene.add( mesh );
lod.addLevel(mesh, 75);
}
});
},
// called while loading is progressing
function (xhr) {
console.log((xhr.loaded / xhr.total * 100) + '% loaded');
},
// called when loading has errors
function (error) {
console.log('An error happened');
console.log(error);
}
);
var light = new THREE.HemisphereLight();
scene.add(light);
scene.add(lod);
var animate = function () {
requestAnimationFrame(animate);
renderer.render(scene, camera);
};
animate();
Only a few element of the model is displayed (a screenshot is available here http://the.ndero.ovh/file/threejs.png ). The whole scene is correctly displayed if i use scene.add(mesh) instead of lod.addLevel
Is this expected ?