I am currently developing a project using modular Three.js with TypeScript. Although the scene is being created successfully, I am facing an issue where no elements are being rendered on the canvas. Below is the snippet of my code:
import * as THREE from 'three/build/three.module'
class App {
private scene = new THREE.Scene();
private camera;
private renderer = new THREE.WebGLRenderer();
private container = document.getElementById('widget');
constructor() {
this._init();
let geometry = new THREE.BoxGeometry(1, 1, 1);
let material = new THREE.MeshBasicMaterial({ color: 0x00ff00, wireframe: true });
let cube = new THREE.Mesh(geometry, material);
this.scene.add(cube);
}
_init() {
this.camera = new THREE.PerspectiveCamera(45, this.container.clientWidth / this.container.clientHeight, 1, 1000);
this.camera.position.z = 5;
this.scene.add(this.camera)
this.renderer.setSize(this.container.clientWidth, this.container.clientHeight);
this.container.appendChild(this.renderer.domElement);
}
}
new App()