Struggling with integrating Skybox in THREE.js

My console is not showing any errors. I am utilizing the live server VS code extension to execute the JS code. Can someone please assist me?"

HTML:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        body { margin: 0; }
        canvas { display: block; }
    </style>
</head>
<body>
    <script src="https://threejs.org/build/three.js"></script>
    <script src="/script.js"></script>
</body>
</html>

Script:

var scene, camera, renderer;
initialiseScene();
animate();

function initialiseScene() {
    //scene
    scene = new THREE.Scene();

    //FOV, Aspect ratio, Near clip, Far clip
    camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0, 1, 1000);

    //renderer
    renderer = new THREE.WebGLRenderer();
    renderer.setSize(window.innerWidth, window.innerHeight);
    document.body.appendChild(renderer.domElement);

}

//AXES
var axesNavigation = new THREE.AxesHelper(100);
scene.add(axesNavigation);

//FLOOR TEXTURE
var loader = new THREE.TextureLoader();

var floorTexture = loader.load('assets/stone_floor.jpg', function ( texture){

    texture.wrapS= texture.wrapT = THREE.RepeatWrapping;
    texture.offset.set(0,0);
    texture.repeat.set(2,2);
});

//FLOOR MATERIAl
var floorMaterial = new THREE.MeshBasicMaterial({ map: floorTexture, side: THREE.DoubleSide });
var floorGeometry = new THREE.PlaneGeometry(1000, 1000, 10, 10);
var floor = new THREE.Mesh(floorGeometry, floorMaterial);
floor.position.y = -0.5;
floor.rotation.x = Math.PI/2;
scene.add(floor);

//SKYBOX

let materialArray = [];
let texture_ft = new THREE.TextureLoader().load( 'assets/hot_ft.png');
let texture_bk = new THREE.TextureLoader().load( 'assets/hot_bk.png');
let texture_up = new THREE.TextureLoader().load( 'assets/hot_up.png');
let texture_dn = new THREE.TextureLoader().load( 'assets/hot_dn.png');
let texture_rt = new THREE.TextureLoader().load( 'assets/hot_rt.png');
let texture_lf = new THREE.TextureLoader().load( 'assets/hot_lf.png');

materialArray.push(new THREE.MeshBasicMaterial( { map: texture_ft }));
materialArray.push(new THREE.MeshBasicMaterial( { map: texture_bk }));
materialArray.push(new THREE.MeshBasicMaterial( { map: texture_up }));
materialArray.push(new THREE.MeshBasicMaterial( { map: texture_dn }));
materialArray.push(new THREE.MeshBasicMaterial( { map: texture_rt }));
materialArray.push(new THREE.MeshBasicMaterial( { map: texture_lf }));

for (let i = 0; i < 6; i++)
  materialArray[i].side = THREE.BackSide;

let skyboxGeo = new THREE.BoxGeometry( 10000, 10000, 10000);
let skybox = new THREE.Mesh( skyboxGeo, materialArray );
scene.add( skybox );


//ANIMATE
function animate() {
    requestAnimationFrame(animate);
    render();
}
function update(){};
//RENDER
function render() {
    renderer.render(scene, camera);
}

I was encountering errors in the console indicating that some functions were renamed or changed. I fixed these issues but the application still shows a blank canvas without any output.

Answer №1

Create a new camera with the code: camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0, 1, 1000);

It seems that the far value of your camera is too small for the skybox dimensions. The skybox has a width, height, and depth of 10.000, which means it's not visible within the camera's view frustum. Try increasing the far value to 20000.

Alternatively, you can load your cube texture using CubeTextureLoader as shown in the following example. Then assign the resulting CubeTexture to Scene.background.

Check out this link for more information.

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

What is the best way to conceal a row when a particular field is devoid of content?

Is it possible to hide an entire table row if a field is empty? For example: https://i.sstatic.net/tMW7L.png If a certain field is empty, I want the entire row to be hidden, either using JavaScript or jQuery. I have tried some methods but none of them fu ...

The functionality of the Sticky state is not effective when it is implemented on a state that contains parameters

It appears that the sticky state feature does not function properly when there are parameters involved. For example: $stateProvider .state('store', { url: '/store', abstract: true, onEnter: ...

Is there a way to invoke a high-order function multiple times within the code?

const x = { a:1 }; (function q({a}){ console.log(a); return a; })(x); // unable to execute console.log(q(x)) I'm encountering an issue trying to run line 6. Why is this happening? The console works in line 3 when I remove line 6: Error: q is n ...

What is the best way to convert items from a foreach loop into a JSON string using the json_encode() function in PHP?

I want to populate a string with all the emails fetched from the database, in order to use JavaScript for checking if the email entered by a user in a form field is already registered. I'm attempting to utilize the json_encode() function. $connec ...

The 'exhaustive-deps' warning constantly insists on requiring the complete 'props' object instead of accepting individual 'props' methods as dependencies

This particular issue is regarding the eslint-plugin-react-hooks. While working in CodeSanbox with a React Sandbox, I noticed that I can use individual properties of the props object as dependencies for the useEffect hook: For instance, consider Example ...

Is the script failing to retrieve the innerHTML content?

Here is a snippet of HTML code: <div id="team_players"> <h3>Players</h3> <button class="bold-btn" onclick="teamAct('player_list');">Refresh List ↻</button> <table> <thead> <tr> ...

Tips for displaying a sub-menu upon hovering

I am attempting to display the list of sub-menu items when hovering over the main menu item. I have tried using the following CSS code, but it did not work as expected. Any assistance will be greatly appreciated. CSS: summary.header__menu-item.list-menu__ ...

tips for asynchronously loading cloud endpoints APIs

gapi.client.load('myapi1', 'v1', function() { gapi.client.load('myapi2', 'v1', function() { gapi.client.load('myapi3', 'v1', function() { $rootscope.$broadcast( ...

What could be the reason for my React/HTML select element occasionally failing to display the default selected value?

I am currently working on creating a select element in Reactjs/HTML and I am facing an issue with setting a default value based on a component variable. Essentially, the default value of the select should be the id of a component. This is my current imple ...

Exploring the possibilities of combining mixitup with Vue.js 2.0 Component

Struggling to implement mixitup on vue.js; however, every time I check the mixitup target, it shows 0 elements in the container (mixer.getStatus().totalShow) Below is my complete vue.js component code: <template> <section class="main-co ...

How can I implement Jquery ajax calls in various JavaScript functions?

I'm encountering an issue with a particular function in my code function readComm(){ $.post("something.php", {read:"read"}, function(data){ retVal = $.trim(data).toString(); console.log(retVal); return retVal; }); } T ...

Scrape JSON Data and Convert Military Time to Standard Time Using JavaScript

I have a question about scraping JSON data from a URL. The timestamps are in military time and I'm looking for a way to convert them to standard time on the client side. Here is the JSON snippet: [ { SaturdayClose: "21:00", SaturdayOpen: " ...

Alert! Server node encountered an issue while handling the response: process.nextTick(function(){throw err;});

Currently, I am working on a simple application to familiarize myself with Mongo, Express, and Node. An issue arises when I attempt to utilize res.json(docs) in the success conditional during the GET request, generating an error process.nextTick(function( ...

Is it possible to download multiple files using a single ajax call upon success of a click function?

In my file, there are 2 anchor tags with their respective href links. I am triggering both anchor tags at ajax call success. <a id="exportExcelFatturaIcon" href ="${createLink(action: 'downloadExcel', params: [fileName:excelFileName])}" hidde ...

HTML5 input placeholder adapts its size and position dynamically as data is being

During my interaction with the input fields on my bank's website, I noticed that the placeholder text undergoes a unique transformation. It shrinks in size and moves to the upper-left corner of the input field while I am entering information. Unlike t ...

The issue with triggering button events in JavaScript

I've integrated a jquery modal popup for saving uploaded files related to a specific device. The modal appears, the cancel button functions correctly, but I am struggling to trigger the onclick event for the Save button... This is what I have impleme ...

Integrate the dateFilter function into a service within an AngularJS application

Is there a way to include filters in AngularJs services? I've been experimenting app.factory('educationService', [function($rootScope, $filter) { // ..... Some code // What I want console.log(dateFilter(new Date(), 'yyyy ...

JSON string inside a string-type in AWS model

My goal is to create a basic model that can accept a JSON string instead of defining all variables/elements upfront. The model will have an "options" element which will hold a JSON string. Below is the structure of my model. { "$schema": "http://json-sch ...

Obtain the content of every cell in a constantly updating table

I have created a dynamic table as shown below: <table id="sort" class="table"> <thead> <tr> <th>Column Name from DB*</th> <th>Record Le ...

Having trouble getting my angular form validation to function properly

Even though I disabled Bootstrap's validation while using Angular, the validation for every input field still doesn't work. It seems like I have everything set up correctly. My code looks like this below with no success on input validation: < ...