The skybox in Three.js functions perfectly when scaled small, but mysteriously turns black when scaled

After successfully creating a skybox with the provided code, I ran into an issue where it displayed perfectly at 1,000 x 1,000 x 1,000 dimensions. However, upon expanding it to 10,000 x 10,000 x 10,000, it only appeared as black. Is there a specific setting that needs to be adjusted in order to accommodate a larger skybox?

var ambientLight = new THREE.AmbientLight(0x000044);
scene.add(ambientLight);

var directionalLight = new THREE.DirectionalLight(0xff8040);
directionalLight.position.set(1, 1, 1).normalize();
scene.add(directionalLight);

// Incorporating the skybox
var directions  = ["miramar3.jpg", // right of me
"miramar1.jpg", // left of me
"miramar4.jpg", // above me
"miramar5.jpg", // beneath me
"miramar6.jpg", // behind me
"miramar2jpg", // in front of me
];
var skyGeometry = new THREE.CubeGeometry( 1000, 1000, 1000 );    

var materialArray = [];
for (var i = 0; i < 6; i++)
    materialArray.push( new THREE.MeshBasicMaterial({
        map: THREE.ImageUtils.loadTexture( directions[i] ),
        side: THREE.BackSide
    }));
var skyMaterial = new THREE.MeshFaceMaterial( materialArray );
var skyBox = new THREE.Mesh( skyGeometry, skyMaterial );
skyBox.position.y += 200;
scene.add( skyBox );

Answer №1

The issue at hand appears to stem from camera clipping in your setup. Camera clipping refers to the fact that anything located beyond the far-plane of the camera is not visible and therefore appears as black in your scene.

According to the documentation on perspective cameras in Three.js, a typical configuration involves setting a near-plane value of 1 and a far-plane value of 1000:

var camera = new THREE.PerspectiveCamera( 45, width / height, 1, 1000 );

If you have set up your camera in this manner and are using a skybox with dimensions of 10,000, each side of the cube may be positioned too far away (beyond the far-plane) and consequently gets clipped.

Answer №2

When creating a new scene, you can name it anything you want.

var skyScene = new THREE.Scene();

You can then place your box in this scene and render it before your main content.

To set this up, ensure that

renderer.autoClear = false,

and in your render loop, include something like

renderer.clear();
renderer.render( scene , camera );
renderer.render( skyScene , camera );

This might require some additional logic, but the basic concept is there. By separating the background from the rest of the geometry in this way, you can avoid managing them together. One way to prevent depth writing is by including

depthWrite: false 

in the parameters passed to the material.

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

Incorporating a separate PHP file which includes JavaScript code

I've been struggling to make this code work. In my footer file, I have the following: footer.php: <script type="text/javascript"> $(document).ready(function(){ $.ajax({ url: '', type: 'GET', dataType: "script", success: ...

"Troubleshooting problem with res.send function in a callback with Node.js

My node.js script has two main functions: It starts an HTTP server that listens for POST requests from a browser. It initiates a socket connection to a Java server. When a request comes from the browser, data is sent to the Java server using the socket. ...

Tips for retrieving document body from a script embedded within document.write

I urgently need assistance! I am currently developing an application that retrieves a report from an API, and the JSON response includes HTML content. Unfortunately, due to the JSON format, I cannot directly open this in a new browser window. Within my sc ...

Executing a program on a website that records every single keystroke made while the webpage is active

Just to clarify, I am not developing a keylogger. I am working on a website for a video game where users can earn items by completing specific in-game actions, like typing something in the chat. Given the nature of this game, I believe the most effective ...

Unable to save the session identifier from the response headers while utilizing sessions in react/frappe framework

I am attempting to retrieve the session id (sid) from the response headers in a unique scenario. My client application is situated on a local environment, while my API is hosted on an ERP Next server. Upon sending a login request from the React app, I am ...

HTML // jQuery - temporarily mute all audio for 10 seconds after page reload

Is there a way to automatically mute all audio sounds on my website for the first 10 seconds after it is reloaded, and then unmute again? <audio id="musWrited" autoplay> <source src="sound/soundl.mp3" type="audio/mp3" /> // < ...

Where should I place my custom menu script in Wordpress and how do I do it?

I am currently exploring the realms of PHP, Wordpress, and Javascript as I endeavor to transform my website, crafted with CSS and HTML, into a dynamic theme for Wordpress using PHP. One particular feature on my site is an off-screen menu that smoothly ope ...

Unexpected color is displayed when using Three.js setHSL() method

setColorUsingHSL(hue, saturation, lightness) - Use this function to set the color based on provided HSL values. Remember, these values should be between 0 and 1. When I call material.color.setColorUsingHSL(0.5, 1, 0.5), why am I seeing cyan instead of yel ...

Is it possible to resize an image in a single direction?

Is there a way to scale in one direction only? Typically, the scale function will scale the canvas equally in both the x and y directions. But what if I want to scale, for example, a polyline or group of lines only in the x direction without affecting the ...

Retrieve SQL data and store it in a JavaScript variable

Need assistance with fetching data from SQL and storing it in a JavaScript variable. I have already connected PHPMyAdmin to my website. I am attempting to retrieve two variables (date) from my SQL table. JAVASCRIPT: var countdown_48 = new Date; countdow ...

How can `localePath()` be utilized to create a dynamic route with Nuxt i18n?

I currently have this route set up in my i18n.config.js: { pages: { 'rental/_id': { nl: '/verhuur/:id', en: '/rental/:id', de: '/mietbestand/:id', }, } } When attempting to link to this page in my ...

Issue: failure of child element - the provided path is incorrect: "users/[object Object]", when implementing Firebase with Next.js

Having trouble with the identityNumber variable, which is giving an error message stating that a string is required. However, my identity number is already a string. Any assistance would be greatly appreciated. Additionally, the aim is to make the identity ...

Converting Byte strings to Byte arrays in Node.js using JavaScript

Currently facing a challenge while trying to complete the pythonchallenge using JS and Node. Stuck on challenge 8 where I need to decompress a string using bzip2: BZh91AY&SYA\xaf\x82\r\x00\x00\x01\x01\x80\x ...

An in-depth guide on implementing debounce functionality for `keyup` events in Vue.js

I am attempting to detect when the user begins typing and stops typing using the debounce function. I experimented with Lodash and Underscore.js. On my textArea v-on:keyup="handler($event)" handler: function(e) { ...

The error message "Property 'id' is missing on type 'T'" is indicating the absence of the 'id' property in the

I am currently working on a React component that serves as a table and is designed to handle various types of data. The structure of the component is defined as follows: type SimpleTableProps<T> = { data: Array<T>; ... }; const SimpleTabl ...

JQuery tips and tricks: How to create a hover effect for an image positioned behind

Is there a way to achieve hover on an element that is positioned behind another? I am working with two images and have come across others with the same issue. However, the solutions they found were just workarounds rather than true solutions to achieving a ...

Placing the word "repeatedly" in a d3 js tree

I am currently working on building a tree structure and incorporating edge labels. The tree allows nodes to be dynamically added using a plus button that appears when you click on a parent node. One issue arises when adding a new child. (apologies for the ...

Argument contains an invalid left-hand side - Reference error

Currently, I have a straightforward JavaScript function in which I iterate over a series. After that, I add a value to an array and then assign it to an object. This process is part of my work on creating a c3 combination chart. However, I encountered an ...

Angular JS may encounter a cross domain problem when attempting to post on a third-party website

HTML Code: <div ng-app="myApp" ng-controller="myController"> <div> <input type="button" data-ng-click="submit()" ...

The type '(dispatch: Dispatch<any>, ownProps: OwnProps) => DispatchProps' does not match the parameter type 'DispatchProps'

Currently, I am working on a React application using Redux and TypeScript. I came across this insightful article that provided guidance on creating types for the mapStateToProps and mapDispatchToProps functions. Below is the code for my container: import ...