浏览代码

Add a way to enumerate and select a camera configuration to the CameraImage sample scene. This affects the resolution of the image returned by XRCameraSubsystem.TryGetLatestImage.

This sample will not currently work; this demonstrates new functionality not yet publicly released.
/1.5-preview
Tim Mowrer 6 年前
当前提交
a7323acc
共有 6 个文件被更改,包括 894 次插入62 次删除
  1. 811
      Assets/Scenes/CameraImage.unity
  2. 30
      Assets/Scripts/TestCameraImage.cs
  3. 48
      Packages/manifest.json
  4. 2
      ProjectSettings/ProjectVersion.txt
  5. 54
      Assets/Scripts/CameraConfigController.cs
  6. 11
      Assets/Scripts/CameraConfigController.cs.meta

811
Assets/Scenes/CameraImage.unity
文件差异内容过多而无法显示
查看文件

30
Assets/Scripts/TestCameraImage.cs


// See CameraImage.FormatSupported for a complete list of supported formats.
var format = TextureFormat.RGBA32;
if (m_Texture == null)
if (m_Texture == null || m_Texture.width != image.width || m_Texture.height != image.height)
m_Texture = new Texture2D(image.width, image.height, format, false);
// Convert the image to format, flipping the image across the Y axis.

#if UNITY_2018_2_OR_NEWER
// In 2018.2+, Texture2D allows us write directly to the raw texture data
// Texture2D allows us write directly to the raw texture data
image.Convert(conversionParams, new IntPtr(rawTextureData.GetUnsafePtr()), rawTextureData.Length);
#else
// In 2018.1, Texture2D didn't have this feature, so we'll create
// a temporary buffer and perform the conversion using that data.
int size = image.GetConvertedDataSize(conversionParams);
var rawTextureData = new NativeArray<byte>(size, Allocator.Temp);
var ptr = new IntPtr(rawTextureData.GetUnsafePtr());
image.Convert(conversionParams, ptr, rawTextureData.Length);
m_Texture.LoadRawTextureData(ptr, rawTextureData.Length);
rawTextureData.Dispose();
#endif
// We must dispose of the CameraImage after we're finished
// with it to avoid leaking native resources.
image.Dispose();
try
{
image.Convert(conversionParams, new IntPtr(rawTextureData.GetUnsafePtr()), rawTextureData.Length);
}
finally
{
// We must dispose of the CameraImage after we're finished
// with it to avoid leaking native resources.
image.Dispose();
}
// Apply the updated texture data to our texture
m_Texture.Apply();

48
Packages/manifest.json


{
"dependencies": {
"com.unity.xr.arcore": "1.0.0-preview.23",
"com.unity.xr.arfoundation": "1.0.0-preview.20",
"com.unity.xr.arkit": "1.0.0-preview.17"
}
}
"dependencies": {
"com.unity.ads": "2.0.8",
"com.unity.analytics": "3.0.9",
"com.unity.collab-proxy": "1.2.11",
"com.unity.package-manager-ui": "2.0.3",
"com.unity.purchasing": "2.0.1",
"com.unity.textmeshpro": "1.3.0",
"com.unity.xr.arcore": "1.0.0-preview.23",
"com.unity.xr.arfoundation": "1.0.0-preview.20",
"com.unity.xr.arkit": "1.0.0-preview.17",
"com.unity.modules.ai": "1.0.0",
"com.unity.modules.animation": "1.0.0",
"com.unity.modules.assetbundle": "1.0.0",
"com.unity.modules.audio": "1.0.0",
"com.unity.modules.cloth": "1.0.0",
"com.unity.modules.director": "1.0.0",
"com.unity.modules.imageconversion": "1.0.0",
"com.unity.modules.imgui": "1.0.0",
"com.unity.modules.jsonserialize": "1.0.0",
"com.unity.modules.particlesystem": "1.0.0",
"com.unity.modules.physics": "1.0.0",
"com.unity.modules.physics2d": "1.0.0",
"com.unity.modules.screencapture": "1.0.0",
"com.unity.modules.terrain": "1.0.0",
"com.unity.modules.terrainphysics": "1.0.0",
"com.unity.modules.tilemap": "1.0.0",
"com.unity.modules.ui": "1.0.0",
"com.unity.modules.uielements": "1.0.0",
"com.unity.modules.umbra": "1.0.0",
"com.unity.modules.unityanalytics": "1.0.0",
"com.unity.modules.unitywebrequest": "1.0.0",
"com.unity.modules.unitywebrequestassetbundle": "1.0.0",
"com.unity.modules.unitywebrequestaudio": "1.0.0",
"com.unity.modules.unitywebrequesttexture": "1.0.0",
"com.unity.modules.unitywebrequestwww": "1.0.0",
"com.unity.modules.vehicles": "1.0.0",
"com.unity.modules.video": "1.0.0",
"com.unity.modules.vr": "1.0.0",
"com.unity.modules.wind": "1.0.0",
"com.unity.modules.xr": "1.0.0"
}
}

2
ProjectSettings/ProjectVersion.txt


m_EditorVersion: 2018.1.1f1
m_EditorVersion: 2018.3.0b9

54
Assets/Scripts/CameraConfigController.cs


using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.XR.ARExtensions;
using UnityEngine.XR.ARFoundation;
[RequireComponent(typeof(Dropdown))]
public class CameraConfigController : MonoBehaviour
{
List<string> m_ConfigurationNames;
Dropdown m_Dropdown;
public void OnValueChanged(Dropdown dropdown)
{
var cameraSubsystem = ARSubsystemManager.cameraSubsystem;
if (cameraSubsystem == null)
return;
var configurationIndex = dropdown.value;
// Check that the value makes sense
if (configurationIndex >= cameraSubsystem.GetConfigurationCount())
return;
// Get that configuration by index
var configuration = cameraSubsystem.GetConfiguration(configurationIndex);
// Make it the active one
cameraSubsystem.SetConfiguration(configuration);
}
void Awake()
{
m_Dropdown = GetComponent<Dropdown>();
m_ConfigurationNames = new List<string>();
}
void Update()
{
m_Dropdown.ClearOptions();
var cameraSubsystem = ARSubsystemManager.cameraSubsystem;
if (cameraSubsystem == null)
return;
// Typically, you would only need to do this once.
m_ConfigurationNames.Clear();
foreach (var config in cameraSubsystem.Configurations())
m_ConfigurationNames.Add(config.ToString());
m_Dropdown.AddOptions(m_ConfigurationNames);
}
}

11
Assets/Scripts/CameraConfigController.cs.meta


fileFormatVersion: 2
guid: 94b653a1faa6f4749ad83e77bcddfab4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存