Using NEXT JS, Three js is able to convert an equirectangular panorama into cubemap format

I'm currently working on converting an equirectangular panorama image into cubemap format using NEXT JS. The scene is being rendered but I'm facing an issue where the background isn't applying, and surprisingly, no errors are showing up!

import { useLoader, useThree } from "@react-three/fiber";
import * as THREE from "three";

const Background = (props) => {
    const texture = useLoader(THREE.TextureLoader, "/autoshop.jpg");

    const { gl } = useThree();

    const formatted = new THREE.WebGLCubeRenderTarget(
        texture.image.height
    ).fromEquirectangularTexture(gl, texture);

    console.log("formatted", formatted);

    return <primitive attach="background" object={formatted} />;
};

export default Background;

This component is then wrapped inside Suspense:

<Suspense fallback={null}>
    <Background />
</Suspense>

Answer №1

After reading a helpful comment from @Marquizzo, I discovered an alternative method to achieve the same result. Instead of using the following code:

const formatted = new THREE.WebGLCubeRenderTarget(
    texture.image.height
).fromEquirectangularTexture(gl, texture);

I can simply use:

texture.encoding = THREE.sRGBEncoding;
texture.mapping = THREE.EquirectangularReflectionMapping;

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

Achieving function components within React Router Dom V6

I need help with keeping my sidebar as a continuous function component without re-rendering every time the page changes from "/dashboard" to "/chat". This is how it looks currently: <div className="flex flex-col "> <BrowserRouter> ...

React/NextJS: Firebase Realtime Database displaying the message "Error: Client is offline"

Encountering an occasional error when using React with NextJS to fetch data from a Firebase Realtime Database. Unhandled Runtime Error Error: Error: Client is offline. Currently utilizing Firebase version 9.0.1 for React. The initialisation and configura ...

The Private Route feature is failing to display the About Component

I have my private routes set up in App.js, and all the other components within the private routes render correctly except for the About Component. Initially, I was receiving an error message stating something like "expected a string but got an object." N ...

Customizing font size in React with Material UI: A comprehensive guide on adjusting the font size of the Select component

I'm currently working on a web application that utilizes React along with Material UI. My goal is to adjust the font size of the Select component. I've attempted to achieve this by utilizing the MenuProps property, as shown in the following code ...

Trouble retrieving desired data from an array of objects in React Native

I'm having trouble retrieving values from an array of objects in my state. When I try to access the values, it only prints out "[Object Object]". However, when I stored the values in a separate array and used console.log, I was able to see them. Here ...

Combining Data in React Arrays

I have an array with different group types and I need to merge the results if the grouptype is the same. const locationss = [ { grouptype: "Name1", id: "1", servicetype: [ { name: "Morning", price: "5& ...

Encountering an issue where the sharp module fails to build during yarn install

After updating both Node and Yarn, I encountered an issue while trying to run yarn install on my NextJS project. The error message that showed up is as follows: ... ➤ YN0007: │ sharp@npm:0.29.3 must be built because it never has been before or the last ...

Auto Suggest: How can I display all the attributes from a JSON object in the options list using material-ui (@mui) and emphasize the corresponding text in the selected option?

Currently, I am facing a requirement where I need to display both the name and email address in the options list. However, at the moment, I am only able to render one parameter. How can I modify my code to render all the options with both name and email? ...

Unveiling the Power of Ionic and React for Component Repetition

I'm having trouble figuring out how to repeat my component multiple times using react in Ionic. Can someone assist me with this? Here's an example: In my Component.tsx file, I have the following code: import React from 'react'; import ...

Website created using React without the use of Javascript

Currently, I am considering migrating one of my websites that is built using Python-Flask and Jinja2. The reason behind this decision is primarily due to the limitations of Jinja2's developer experience and the fact that Python is not typed by default ...

Changing the CSS background in React when updates occur

Currently working on toggling the CSS background image within this React application. The images have been successfully imported and a variable called "image" is set to the imported image as the iteration increases/decreases with each click. The issue I&a ...

Adjust the dimensions of the icon

My current project involves creating a sidebar with icons and associated text to represent each icon. However, I encountered an issue while trying to adjust the size of the icons within the sidebar using the "useStyles()" method. For some reason, the size ...

Why am I unable to export dynamic routes with "use client" in Next.js 13 when using the App Router?

I am currently working with Next.js 13 using the App Router and have a page that utilizes dynamic routes. Everything runs smoothly when I test the server locally (e.g., localhost:3000//tickets/2), but I encounter prerender errors when attempting to export ...

Creating a unique LinearProgress component using React and MaterialUI with a beautiful

I am looking to enhance the appearance of MaterialUI's LinearProgress element by creating a gradient design for the completeness bar. My goal is to have the left side of the bar display color A and the right side show color B, with the transition betw ...

Guide to deploying a React Application to Netlify while organizing the client and server directories

I'm facing some confusion while attempting to deploy an application to Netlify that consists of both client and server folders. I initially tried running npm build on the main directory which contains both folders, but it did not yield the desired res ...

react-select seems to have a glitch where only the first option is rendering, but it is not visible. Additionally, when I try to select an option, the entire array seems to be disappearing

My backend is providing me with an array of flavors. This is how I am using it in my jsx: <div className="mb-3"> <Select options={flavorOptions} onChange={onSelectOption} value={flavor} /> </div> I have formatted the ...

Switch out the icons within a return statement in JavaScript

Help! I have 5 empty star icons (<StarBorderIcon/>) displayed for a product on the material-ui website. I need to replace them with filled star icons (<StarIcon/>) based on the rating entered into a function. I attempted to use replace(), but i ...

The Drawer element is not displaying the desired styling as expected

I have a simple question about styling a Drawer component in React. When I use the sx property to add styles, they are being applied to the parent block of the Drawer instead of the Drawer itself. As a result, the styles are not appearing as expected on th ...

Showcase the data stored in express-session in a React application

I set up an OpenID passport.js strategy (passport-steam) for my MERN-stack application. The currently logged-in user's data is stored in an express-session, accessible through the object req.session.passport.user in my Node.js file. What is the most ...

Preserve the selected Material UI Tab in ReactJS even after refreshing the page

Hey there, I've been using React Material UI Tab and ran into an issue where the tab selection is lost on page refresh. Does anyone know how to fix this problem? This pertains to a code snippet for the material ui tab component. class SimpleTabs exte ...