Trying to create a basic scene using Three.js for some experimentation, but facing an unknown issue.
The console keeps displaying an error stating that Three.Scene() is not a constructor, whether I import my own download of Three or use the cdnjs.
import * as Three from 'https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.js';
let scene, camera, renderer, cube;
function init() {
scene = new Three.Scene();
camera = new Three.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
renderer = new Three.WebGLRenderer({ antialias: true });
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
const material = new Three.MeshBasicMaterial({ color: 0x00ff00 });
scene.background = new Three.color(FFFF);
const geometry = new Three.BoxGeometry(1, 1, 1);
cube = new Three.Mesh(geometry, material);
scene.add(cube);
camera.position.z = 5;
}
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
}
init();
window.addEventListener('resize', onWindowResize, false)
function animate() {
requestAnimationFrame(animate);
cube.rotation.x += 0.1;
cube.rotation.y += 0.1;
renderer.render(scene, camera);
}
animate();
Tried searching for a solution, but all similar issues were caused by typos or incorrect imports.
Here's the HTML code:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>THREE Test</title>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<script type="module" src="./code.js"></script>
</body>
</html>