js-skybox-mapping is a demo project showcasing how to wrap a flat texture image file onto a 3D skybox using Three.js. The project currently supports multiple cubemap layouts (3x2, 3x4 etc) and supports two mapping methods:
-
UV Mapping: This method involves manually assigning UV coordinates to accurately map the texture onto the skybox faces.
-
Material Array: With this approach, each face of the skybox gets its own material. Use this method if you plan on adding video texture to the skybox
A cubemap is a type of texture used to represent a 3D environment. It is a collection of six square images arranged like the faces of a cube. Each texture represents a view from a different direction: up, down, left, right, front, and back.These images are often used in computer graphics to create reflections, skyboxes, or environment mapping effects. Cubemaps can be generated in different layouts depending on how the faces of the cube are arranged. A couple of layouts are shown below
3x4 Layout | 2x3 Layout |
---|---|
A skybox is a method used in computer graphics to create the illusion of a vast environment surrounding a scene. It typically involves wrapping a cube or a sphere with textures representing a distant background. By rendering the scene inside this cube, with the camera at the center, it appears as though the scene is surrounded by the textures of the skybox.
- Mapping any cubemap layout onto a cube skybox
- Supports video textures as well
- Multiple mapping methods - Manual UV Mapping and Assigning Material Array
- Support for Spherical textures
To run the project locally, follow these steps:
- Clone this repository to your local machine.
- Navigate to the project directory.
- Run
npm install
thennpm run dev
. This will start a localvite
server - Open
localhost:5173
in your browser
To add a new cubemap layout, follow these steps:
- Prepare your cubemap image in the appropriate format.
- Add the image to the
images
directory. - Create a new
Variant
in theVARIANTS
object incube.js
with a layout name, the path to the layout image and a list denoting how the faces are structured in the layout. - Save your edits and refresh the project in your browser. Your new variant will be available for selection in the GUI under "Variant" dropdown
Suppose you have a cubemap layout image with 3 rows and 2 columns similar to demo_cubemap3x2.png. Follow these steps to add it:
- Place the image in the images folder.
- In
cube.js
, add a new variant to theVARIANTS
object. Use the following structure:
CubeMap3x2: new Variant("DemoCubeMap3x2", cubemap3x2Txt, [
[FACES.FRONT, FACES.BACK], // First row
[FACES.LEFT, FACES.UP], // Second row
[FACES.RIGHT, FACES.DOWN], // Third row
])
In this variant:
- Each list inside the outer list represents a row of the cubemap layout.
- Each item within a row list corresponds to a cell in the layout, specifying which face of the cube it represents.
The images used in this project are sourced from Camera 360 V2 Unreal Engine plugin.
This project is licensed under the MIT License - see the LICENSE file for details.
While the future support of this project is uncertain, anyone is welcome to fork and use this framework to build their own codebase. Feel free to customize and extend it based on your requirements.