constructor(container) { this.renderWrapper = this.render.bind(this); this.objects = []; this.container = container; this.width = this.container.offsetWidth; this.height = 500; this.loader = new STLLoader(); this.fov = 45; this.camera = new THREE.PerspectiveCamera(this.fov, this.width / this.height, 1, 1000); this.scene = new THREE.Scene(); this.scene.add(this.camera); // Set up the viewer this.setupRenderer(); this.setupGrid(); this.setupLight(); // Set up OrbitControls this.controls = new OrbitControls(this.camera, this.renderer.domElement); this.controls.minDistance = 5; this.controls.maxDistance = 30; this.controls.enableKeys = false; this.loadFile(); }
this.loader.load(this.container.dataset.endpoint, geo => { const obj = new MeshObject(geo); this.objects.push(obj); this.scene.add(obj); this.start(); this.setDefaultCameraPosition(); });
setupGrid() { this.grid = new THREE.GridHelper( 20, 20, 0x000000, 0x000000, ); this.scene.add(this.grid); }
setupLight() { // Point light illuminates the object const pointLight = new THREE.PointLight(0xffffff, 2, 0); pointLight.castShadow = true; this.camera.add(pointLight); // Ambient light illuminates the scene const ambientLight = new THREE.AmbientLight(0xffffff, 1); this.scene.add(ambientLight); }