Having just recently started to dabble in THREE.js, I encountered an issue where the code only displays a black screen instead of the intended triangle shape. Can someone assist me in troubleshooting the problem within the code?
<!DOCTYPE html>
<html>
<head>
<title>First Line Object</title>
<style>
body{ margin: 0; }
canvas { width: 100%; height: 100%; }
</style>
</head>
<body>
<script src="js/three.js"></script>
<script>
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera(75, window.innerWidth/window.innerHeight, 0.1, 1000);
var renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
var lineGeom = new Geometry();
lineGeom.vertices = [
new THREE.Vector3(-2,-2, 0),
new THREE.Vector3(2, -2, 0),
new THREE.Vector3(0, 2, 0),
new THREE.Vector3(-2,-2, 0)
];
var lineMat = new THREE.LineBasicMaterial({
color: 0xA000A0,
linewidth: 2
});
var line = new THREE.Line(lineGeom, lineMat, THREE.LineStrip);
scene.add(line);
camera.position.z = 5;
var render = function() {
requestAnimationFrame(render);
renderer.render(scene, camera);
}
render();
</script>
</body>
</html>
Upon analysis, the code is constructed to render a triangle based on the provided vertices in the array. However, an unexpected outcome occurs where only a black screen is visible without the triangle shape. It's crucial to identify and resolve this issue for the desired output.