I am facing an issue with rendering multiple models at the same time. When I try to render them, the display shows up as white and blank with no errors in the console. I am only able to render one model at a time. How can I render multiple models simultaneously? enter image description here
import * as THREE from './threejs/three.module.js';
import {STLLoader} from './threejs/STLLoader.js';
import {OrbitControls} from './threejs/OrbitControls.js';
let scene, camera, renderer, object;
function init(){
scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera(
75,
window.innerWidth / window.innerHeight,
0.1,
10000
);
camera.position.z = 10;
renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
scene.add(object);
let control = new OrbitControls(camera, renderer.domElement);
let light = new THREE.DirectionalLight(0xffffff);
light.position.set(0,0,10);
scene.add(light);
let light2 = new THREE.DirectionalLight(0xffffff);
light2.position.set(0,0,-10);
scene.add(light2);
animate();
loadModels();
}
function animate(){
requestAnimationFrame(animate);
renderer.render(scene, camera);
}
var models = [];
function loadModels(){
loadModel('/左肾占位/NING_XUAN_QING_M_056Y_Violet_001.stl', -5);
loadModel('/左肾占位/NINGXUANQINGM056Y_Turquoise_001.stl', 0);
}
function loadModel(path, positionY){
let loader = new STLLoader();
loader.load(path, (model)=>{
let obj = new THREE.Mesh(
model,
new THREE.MeshLambertMaterial({color: 0x00ff00})
);
obj.scale.set(0.2, 0.2, 0.2);
obj.position.set(0, positionY, 0);
obj.rotation.x = -Math.PI/2;
models.push(obj);
scene.add(obj);
});
}
The model is a Left renal mass comprised of multiple parts, each with its own 3D model file. I need to combine all these parts together to form a complete model.