The cube is visible, but the skybox is nowhere to be found

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.

Answer №1

This section

let skyBoxGeo = new THREE.BoxBufferGeometry(1000, 1000, 1000);
let skyBox = new THREE.Mesh(skyBoxGeo, materialArray); // should be Mesh(), not MeshBasicMaterial()

Instead of that

let skyBoxGeo = new THREE.BoxBufferGeometry(1000, 1000, 1000);
let skyBox = new THREE.Mesh(skyBoxGeo, materialArray); // it must be Mesh(), not MeshBasicMaterial()

You can exclude this line:

scene.add(cube); // since there is no variable named `cube`

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Check the data from the radio button selection

I am facing an issue with reading the values of radio buttons in a list, all of which have the same id. Despite trying to retrieve the value of each individual radio button, my code only reads the value of the first radio button. <script src="//ajax. ...

Employing jQuery to add an element as a sibling rather than a child node

I'm having trouble finding the specific functionality I need. My goal is to add sibling DOM elements to a disconnected node. From what I gather, it should be possible with either .after() or .add(), but for some reason both methods are not working as ...

Is JavaScript capable of producing different results with the same input?

I am currently revising one of my scripts and have come across a perplexing issue. The variable command is an input, and I conducted the following test with identical regular expressions: var parts = command.match(/([^\s"]+(?=\s*|$))|(".+?")/g); ...

Exploring the nuances of various browsers in JavaScript

I am facing an issue where my JavaScript code functions correctly in Internet Explorer, but not in Firefox or Safari. I have a loop that goes through each element and, depending on the variable inside a text box, triggers an alert message. The code snippet ...

What is the best way to incorporate currency formatting into a table using sumtr and datatables?

I have a table where I am utilizing sumtr for the table footer, and displaying all the information within datatables. My requirement is to show all the values as currency. However, I am unable to modify the values after sumtr because it won't be able ...

Listening for key combinations in VueJS using a mounted event listener

I am facing an issue with my global key listener - it only catches single key strokes. How can I modify it to capture combinations like ctrl+enter? mounted() { window.addEventListener ( "keypress", e => { console.log ...

Exploring the possibilities of DOM events within nodeJS and express

Does anyone have experience catching a DOM event with NodeJS and Express? I've been looking into the "socket.io" module but am having trouble using it properly. My goal is to run some code whenever the content of a "file input" changes in the DOM. & ...

Warning: Trying to access an undefined property within an async function in Typescript

Recently, I have been tackling an issue with my API that is built with TypeScript and NodeJS. The problem arises when my Promises seem to not resolve correctly in the following code snippet: async function retrieveData() { return new Promise((reso ...

Tips for updating the firebase access_token with the help of the next-auth credentials provider

Can anyone help me with refreshing the Firebase access token when it expires? I need the token for API authentication, but I can't find any information online regarding next-auth and Firebase. Currently, I am able to retrieve the access token but str ...

Mastering the Art of Concise Writing: Tips to

Is there a way to write more concisely, maybe even in a single line? this.xxx = smt.filter(item => item.Id === this.smtStatus.ONE); this.yyy = smt.filter(item => item.Id === this.smtStatus.TWO); this.zzz = smt.filter(item => item.Id == ...

Is it possible to reload the page using Node.js and Express?

In my small Node and Express application, I am looking to automatically refresh the page when a user connects. I attempted using res.redirect('index.html') in a particular section of code, but encountered an error when trying to connect to the ro ...

Assign values to variables in a JavaScript file using node.js

My tech stack includes node.js, express.js, and either pug or jade. Within my server, I inject a variable called pageId into a view. In the pug view, I utilize this variable using the following script: script. document.addEventListener('DOMConten ...

Developing an interactive website utilizing AngularJS, WCF Service, and SQL Server

Exploring the possibilities of creating a web application, I stumbled upon AngularJS. With plans to incorporate WCF Service and SQL Server into my project, I am intrigued by what these technologies can offer. I want to ensure that AngularJS aligns with my ...

Repeated questions are becoming a common occurrence

I am currently working on a quiz using javascript and HTML, where the questions are stored in a JSON file. However, I am facing an issue where some questions are being repeated multiple times when I run the quiz. How can I prevent this repetition and ensur ...

What is the process of incorporating a select form within a component?

I am currently working on creating a user registration form. Once the form is filled out and the submit button is clicked, I need the values from the form to be displayed in a specific <p id="data></p> component. Can anyone assist me with this ...

Adding a Material UI Tooltip to the header name of a Material UI Datagrid - a step-by-step guide!

I've nearly completed my initial project, but the client is requesting that I include labels that appear when hovering over specific datagrid cells. Unfortunately, I haven't been able to find any solutions on Google for adding a Material UI Tool ...

Reveal and Conceal, the ever-changing show

As I work on my blog, I want to make the layout more compact by having a link that reveals comments and entry forms when clicked. I've seen this feature on other sites as "Comments (5)", but I'm unsure how to implement it myself. Below is a snip ...

The word-wrap malfunction is causing problems, leading to text overflow in a draggable element

Looking for help with a problem I'm facing. I have a draggable div with editable text inside, where users can adjust the text size using an input slider. Is there a way to hide text that extends beyond the border of the image canvas div and reaches t ...

Change the background color of the MUI ToggleButton that is currently selected

I need help figuring out how to change the background color of a selected toggle button. Currently, the buttons are functional but do not visually indicate when one is selected. I would like the first button (Btn 1) to have a default color, and if the us ...

"Utilizing the useState hook to selectively update a portion of the state while keeping the remaining state unchanged

Hello there, I have a question. Is it possible to update just a portion of the state while keeping other parts the same in React? const stuff ={ 'a':'alpha', 'b':'beta' }; const [letter,setLetter]=useState(stuff); ...