Having some trouble getting a skybox to appear along with a rotating cube in my project. The rotating cube is visible, but the skybox isn't showing up.
- Running the project on a local web server
- Tried copying and pasting from a tutorial that worked fine, but encountering issues with my implementation. Both setups seem very similar. Tutorial:
<!DOCTYPE html>
<html>
<head>
<title>FirstPersonGame</title>
<style>
canvas {
width: 100%;
height: 100%
position: absolute;
}
body {
margin: 0px;
}
</style>
</head>
<body>
<script src = "three.min.js"></script>
<script>
var slowDownBy = 8;
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera(90,window.innerWidth/window.innerHeight,0.1,30000);
var renderer = new THREE.WebGLRenderer({antialias:false});
renderer.setSize(window.innerWidth,window.innerHeight);
document.body.appendChild(renderer.domElement);
var geometry = new THREE.BoxGeometry(1,1,1);
var material = new THREE.MeshBasicMaterial({color: 0xffff00})
var cube = new THREE.Mesh(geometry, material);
let materialArray = [];
let SkyBox_1 = new THREE.TextureLoader().load('arid2_bk.jpg');
let SkyBox_2 = new THREE.TextureLoader().load('arid2_dn.jpg');
let SkyBox_3 = new THREE.TextureLoader().load('arid2_ft.jpg');
let SkyBox_4 = new THREE.TextureLoader().load('arid2_lf.jpg');
let SkyBox_5 = new THREE.TextureLoader().load('arid2_rt.jpg');
let SkyBox_6 = new THREE.TextureLoader().load('arid2_up.jpg');
materialArray.push(new THREE.MeshBasicMaterial({map: SkyBox_1}));
materialArray.push(new THREE.MeshBasicMaterial({map: SkyBox_2}));
materialArray.push(new THREE.MeshBasicMaterial({map: SkyBox_3}));
materialArray.push(new THREE.MeshBasicMaterial({map: SkyBox_4}));
materialArray.push(new THREE.MeshBasicMaterial({map: SkyBox_5}));
materialArray.push(new THREE.MeshBasicMaterial({map: SkyBox_6}));
animate();
for (let i = 0; i < 6; i++){
materialArray[i].side = THREE.BackSide;
let skyBoxGeo = new THREE.BoxGeometry(1000,1000,1000);
let SkyBox = new THREE.MeshBasicMaterial(skyBoxGeo,materialArray);
scene.add(SkyBox);
}
scene.add(cube);
camera.position.z = 5;
function animate() {
requestAnimationFrame( animate );
cube.rotation.y += 75/slowDownBy;
renderer.render(scene, camera);
}
</script>
</body>
</html>
Also encountering an error message:
THREE.Object3D.add: object not an instance of THREE.Object3D.