Open tobiaswaggoner opened 2 months ago
Setting up a 360-degree camera for recordings in Unity involves using a cubemap rendering technique. This captures the scene from multiple angles and stitches them together into a single panoramic image. Here's a step-by-step guide:
Create a New Camera in Unity:
Camera
.360Camera
.Position the Camera:
Create and Configure a Render Texture:
Create -> Render Texture
.Script for Capturing 360-Degree Footage:
Camera360Capture.cs
) and attach it to the camera.using UnityEngine;
public class Camera360Capture : MonoBehaviour
{
public int captureWidth = 4096;
public int captureHeight = 2048;
public string savePath = "360Capture.png";
private Camera cam;
private RenderTexture cubemap;
private Texture2D equirect;
void Start()
{
cam = GetComponent<Camera>();
cam.fieldOfView = 90;
cam.aspect = 1.0f;
// Create the cubemap RenderTexture
cubemap = new RenderTexture(captureWidth, captureHeight, 24, RenderTextureFormat.ARGB32);
cubemap.dimension = UnityEngine.Rendering.TextureDimension.Cube;
// Create the equirectangular texture
equirect = new Texture2D(captureWidth, captureHeight, TextureFormat.RGB24, false);
}
void Update()
{
if (Input.GetKeyDown(KeyCode.C))
{
CaptureFrame();
}
}
void CaptureFrame()
{
cam.RenderToCubemap(cubemap);
cubemap.ConvertToEquirect(equirect);
byte[] bytes = equirect.EncodeToPNG();
System.IO.File.WriteAllBytes(savePath, bytes);
Debug.Log("360 Capture saved to " + savePath);
}
void OnDestroy()
{
if (cubemap != null) cubemap.Release();
if (equirect != null) Destroy(equirect);
}
}
Configure the Camera:
Camera360Capture
script to the 360Camera
GameObject.Trigger Capture During Runtime:
C
key during runtime to capture the current view as a 360-degree image.Cubemap Rendering:
The RenderTexture
is set to a cubemap, which captures the scene from six different directions (forward, backward, left, right, up, down). This allows for a complete 360-degree view around the camera.
Field of View (FOV) and Aspect Ratio: The camera's FOV is set to 90 degrees, which is optimal for capturing a cubemap face. The aspect ratio is set to 1.0 to ensure square captures for each direction.
Conversion to Equirectangular: After rendering to the cubemap, the texture is converted to an equirectangular format, which is a standard format for 360-degree images and videos.
Saving the Image: The captured equirectangular image is saved as a PNG file to the specified path, allowing for easy access and further processing or viewing.
By following these steps, you can set up a 360-degree camera in Unity and capture panoramic images during runtime. This setup is useful for creating immersive content for VR applications, virtual tours, and more.
Description:
As a user, I want to start a 360-degree video recording within the application, use the app normally, and stop the recording, so that I can capture immersive video content of my interactions and automatically save it as an MP4 file.
Acceptance Criteria:
Start / Stop Recording UI:
Save MP4 File:
360Capture_YYYYMMDD_HHMMSS.mp4
).Error Handling:
Performance: