浏览代码

Merge branch '2.1-preview' into 2.1-preview-object-tracking

/1.5-preview
Tim Mowrer 5 年前
当前提交
31bbe8cc
共有 30 个文件被更改,包括 1607 次插入351 次删除
  1. 1
      .gitignore
  2. 3
      Assets/Scenes/ImageTracking/ImageTracking.unity
  3. 47
      Assets/Scenes/ImageTracking/Images/Rafflesia.jpg.meta
  4. 33
      Assets/Scenes/ImageTracking/Images/ReferenceImageLibrary.asset
  5. 11
      Assets/Scenes/ImageTracking/Images/unitylogowhiteonblack.jpg.meta
  6. 11
      Assets/Scenes/ImageTracking/Images/QRCode.jpg.meta
  7. 110
      Assets/Scenes/ImageTracking/TrackedImageInfoManager.cs
  8. 11
      Packages/manifest.json
  9. 44
      ProjectSettings/EditorBuildSettings.asset
  10. 4
      ProjectSettings/ProjectVersion.txt
  11. 1001
      Assets/Scenes/CameraImage.unity
  12. 7
      Assets/Scenes/CameraImage.unity.meta
  13. 90
      Assets/Scenes/ImageTracking/Images/QRCode.jpg
  14. 88
      Assets/Scenes/ImageTracking/Images/unitylogowhiteonblack.jpg
  15. 114
      Assets/Scripts/CameraConfigController.cs
  16. 11
      Assets/Scripts/CameraConfigController.cs.meta
  17. 141
      Assets/Scripts/TestCameraImage.cs
  18. 11
      Assets/Scripts/TestCameraImage.cs.meta
  19. 18
      Assets/Scenes/ImageTracking/Images/QRCode.asset
  20. 8
      Assets/Scenes/ImageTracking/Images/QRCode.asset.meta
  21. 9
      Assets/Scenes/ImageTracking/Images/QRCode.png
  22. 18
      Assets/Scenes/ImageTracking/Images/Rafflesia.asset
  23. 8
      Assets/Scenes/ImageTracking/Images/Rafflesia.asset.meta
  24. 18
      Assets/Scenes/ImageTracking/Images/UnityLogoBlack.asset
  25. 8
      Assets/Scenes/ImageTracking/Images/UnityLogoBlack.asset.meta
  26. 48
      Assets/Scenes/ImageTracking/Images/unitylogowhiteonblack.png
  27. 77
      Assets/Scenes/ImageTracking/UnlitTexture.mat
  28. 8
      Assets/Scenes/ImageTracking/UnlitTexture.mat.meta
  29. 0
      /Assets/Scenes/ImageTracking/Images/unitylogowhiteonblack.jpg.meta
  30. 0
      /Assets/Scenes/ImageTracking/Images/QRCode.jpg.meta

1
.gitignore


[Ll]ibrary/
[Ll]ogs/
[Tt]emp/
[Oo]bj/
[Bb]uild/

3
Assets/Scenes/ImageTracking/ImageTracking.unity


m_EditorClassIdentifier:
m_WorldSpaceCanvasCamera: {fileID: 1247506530}
m_DefaultTexture: {fileID: 10305, guid: 0000000000000000f000000000000000, type: 0}
m_TextureReferenceImagePairs:
- texture: {fileID: 2800000, guid: 8185ee60df6f2a44e8c0cf22387f31aa, type: 3}
referenceImage: {fileID: 11400000, guid: a7351be44527d304a85355f98dc6e294, type: 2}
--- !u!1 &1247506529
GameObject:
m_ObjectHideFlags: 0

47
Assets/Scenes/ImageTracking/Images/Rafflesia.jpg.meta


fileFormatVersion: 2
guid: 8185ee60df6f2a44e8c0cf22387f31aa
TextureImporter:
fileIDToRecycleName: {}
internalIDToNameTable: []
serializedVersion: 7
serializedVersion: 9
enableMipMap: 1
enableMipMap: 0
sRGBTexture: 1
linearTexture: 0
fadeOut: 0

compressionQualitySet: 0
textureFormatSet: 0
platformSettings:
- serializedVersion: 2
- serializedVersion: 3
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0

allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: Standalone
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: iPhone
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: Android
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
spriteSheet:
serializedVersion: 2
sprites: []

spriteID:
internalID: 0
secondaryTextures: []
spritePackingTag:
pSDRemoveMatte: 0
pSDShowRemoveMatteOption: 0

33
Assets/Scenes/ImageTracking/Images/ReferenceImageLibrary.asset


m_Script: {fileID: 11500000, guid: 848409ee8ba454f42a5ddff137688a27, type: 3}
m_Name: ReferenceImageLibrary
m_EditorClassIdentifier:
m_GuidLow: 5438900029218683827
m_GuidHigh: 11338665651040755373
- {fileID: 11400000, guid: a7351be44527d304a85355f98dc6e294, type: 2}
- m_SerializedGuid:
m_GuidLow: 5332104792803380197
m_GuidHigh: 185310804734996668
m_SerializedTextureGuid:
m_GuidLow: 3045804918016700000
m_GuidHigh: 12263723139385508072
m_Size: {x: 0.254, y: 0.16891992}
m_SpecifySize: 1
m_Name: Rafflesia
m_Texture: {fileID: 2800000, guid: 8185ee60df6f2a44e8c0cf22387f31aa, type: 3}
- m_SerializedGuid:
m_GuidLow: 4688767676970561261
m_GuidHigh: 9713720137873368247
m_SerializedTextureGuid:
m_GuidLow: 16430241910255274575
m_GuidHigh: 3143750354108030859
m_Size: {x: 0.1, y: 0.1}
m_SpecifySize: 1
m_Name: Logo
m_Texture: {fileID: 2800000, guid: 5a804a4ff1f7e4038b1f1e6f4ad8a02b, type: 3}
- m_SerializedGuid:
m_GuidLow: 5602505921028117032
m_GuidHigh: 208412801924047543
m_SerializedTextureGuid:
m_GuidLow: 288924497207985411
m_GuidHigh: 4143232447317295274
m_Size: {x: 0.05, y: 0.05}
m_SpecifySize: 1
m_Name: QRCode
m_Texture: {fileID: 2800000, guid: a6fd8503774c0402aa403884f5b77f39, type: 3}

11
Assets/Scenes/ImageTracking/Images/unitylogowhiteonblack.jpg.meta


fileFormatVersion: 2
guid: 4560bbb1efc550f4ab718112f77f2454
guid: 5a804a4ff1f7e4038b1f1e6f4ad8a02b
fileIDToRecycleName: {}
internalIDToNameTable: []
serializedVersion: 7
serializedVersion: 9
mipmaps:
mipMapMode: 0
enableMipMap: 1

compressionQualitySet: 0
textureFormatSet: 0
platformSettings:
- serializedVersion: 2
- serializedVersion: 3
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0

allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
spriteSheet:
serializedVersion: 2
sprites: []

spriteID:
internalID: 0
secondaryTextures: []
spritePackingTag:
pSDRemoveMatte: 0
pSDShowRemoveMatteOption: 0

11
Assets/Scenes/ImageTracking/Images/QRCode.jpg.meta


fileFormatVersion: 2
guid: bf2e9553ee29615409e2c1613bed5621
guid: a6fd8503774c0402aa403884f5b77f39
fileIDToRecycleName: {}
internalIDToNameTable: []
serializedVersion: 7
serializedVersion: 9
mipmaps:
mipMapMode: 0
enableMipMap: 1

compressionQualitySet: 0
textureFormatSet: 0
platformSettings:
- serializedVersion: 2
- serializedVersion: 3
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0

allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
spriteSheet:
serializedVersion: 2
sprites: []

spriteID:
internalID: 0
secondaryTextures: []
spritePackingTag:
pSDRemoveMatte: 0
pSDShowRemoveMatteOption: 0

110
Assets/Scenes/ImageTracking/TrackedImageInfoManager.cs


using UnityEngine.XR.ARSubsystems;
using UnityEngine.XR.ARFoundation;
#if UNITY_EDITOR
using UnityEditor;
using UnityEditor.Build;
using UnityEditor.Build.Reporting;
/// <summary>
/// Each XRReferenceImage only stores a Guid, not a Texture2D.
/// At build time, generate a list of source Texture2Ds and store references
/// so that we will have them at runtime.
/// </summary>
class TrackedImageInfoManagerBuildProcessor : IPreprocessBuildWithReport
{
public int callbackOrder { get { return 0; } }
public void OnPreprocessBuild(BuildReport report)
{
var infoManagers = UnityEngine.Object.FindObjectsOfType<TrackedImageInfoManager>();
if (infoManagers == null)
return;
foreach (var infoManager in infoManagers)
infoManager.RebuildDictionary();
AssetDatabase.Refresh();
}
}
#endif
/// <summary>
/// This component listens for images detected by the <c>XRImageTrackingSubsystem</c>
/// and overlays some information as well as the source Texture2D on top of the
/// detected image.

set { m_DefaultTexture = value; }
}
/// <summary>
/// A serializable container for Texture2D and XRReferenceImage pairs.
/// This is used to associate a reference image with the source texture.
/// </summary>
[Serializable]
struct TextureReferenceImagePair
{
[SerializeField]
public Texture2D texture;
[SerializeField]
public XRReferenceImage referenceImage;
public TextureReferenceImagePair(Texture2D texture, XRReferenceImage referenceImage)
{
this.texture = texture;
this.referenceImage = referenceImage;
}
}
/// <summary>
/// A serializable list of Texture2D-ReferenceImage pairs used to lookup
/// a reference image's source Texture2D at runtime.
/// </summary>
[SerializeField, HideInInspector]
List<TextureReferenceImagePair> m_TextureReferenceImagePairs = new List<TextureReferenceImagePair>();
Dictionary<Guid, Texture2D> m_Textures;
// Build a dictionary of Guid to Texture2D
m_Textures = new Dictionary<Guid, Texture2D>();
foreach (var pair in m_TextureReferenceImagePairs)
m_Textures[pair.referenceImage.guid] = pair.texture;
#if UNITY_EDITOR
/// <summary>
/// Rebuilds a serializable list of Texture2D-XRReferenceImage pairs.
/// At runtime, this List is used to populate a dictionary.
/// </summary>
internal void RebuildDictionary()
{
m_TextureReferenceImagePairs = new List<TextureReferenceImagePair>();
var trackedImageManager = GetComponent<ARTrackedImageManager>();
if (trackedImageManager != null && trackedImageManager.referenceLibrary != null)
{
foreach (var referenceImage in trackedImageManager.referenceLibrary)
{
var guid = referenceImage.guid;
var texturePath = AssetDatabase.GUIDToAssetPath(guid.ToString("N"));
if (string.IsNullOrEmpty(texturePath))
{
Debug.LogWarningFormat("Null or empty texturePath for image {0}", guid);
continue;
}
var texture = AssetDatabase.LoadAssetAtPath<Texture2D>(texturePath);
m_TextureReferenceImagePairs.Add(new TextureReferenceImagePair(texture, referenceImage));
}
}
}
#endif
void OnEnable()
{
m_TrackedImageManager.trackedImagesChanged += OnTrackedImagesChanged;

// Update information about the tracked image
var text = canvas.GetComponentInChildren<Text>();
text.text = string.Format(
"trackableId\n{0}\ntrackingState: {1}\nGUID: {2}\nReference width: {3}\nDetected size: {4:0.0000}x{5:0.0000}",
trackedImage.trackableId,
"{0}\ntrackingState: {1}\nGUID: {2}\nReference size: {3} cm\nDetected size: {4} cm",
trackedImage.referenceImage.name,
trackedImage.referenceImage.width,
trackedImage.size.x,
trackedImage.size.y);
trackedImage.referenceImage.size * 100f,
trackedImage.size * 100f);
var planeParentGo = trackedImage.transform.GetChild(0).gameObject;
var planeGo = planeParentGo.transform.GetChild(0).gameObject;

trackedImage.transform.localScale = new Vector3(trackedImage.size.x, 1f, trackedImage.size.y);
// Set the texture
var meshRenderer = planeGo.GetComponentInChildren<MeshRenderer>();
// Look up the texture by Guid
Texture2D texture;
if (!m_Textures.TryGetValue(trackedImage.referenceImage.guid, out texture))
texture = defaultTexture;
meshRenderer.material.mainTexture = texture;
var material = planeGo.GetComponentInChildren<MeshRenderer>().material;
material.mainTexture = (trackedImage.referenceImage.texture == null) ? defaultTexture : trackedImage.referenceImage.texture;
}
else
{

11
Packages/manifest.json


{
"dependencies": {
"com.unity.2d.sprite": "1.0.0",
"com.unity.ads": "2.3.1",
"com.unity.ads": "3.0.3",
"com.unity.analytics": "3.2.2",
"com.unity.collab-proxy": "1.2.16",
"com.unity.multiplayer-hlapi": "1.0.1",

"com.unity.timeline": "1.0.0",
"com.unity.xr.arcore": "1.0.0-preview.24",
"com.unity.xr.arfoundation": "1.0.0-preview.22",
"com.unity.xr.arkit": "1.0.0-preview.23",
"com.unity.xr.legacyinputhelpers": "1.0.0",
"com.unity.xr.arcore": "2.1.0-preview.1",
"com.unity.xr.arfoundation": "2.1.0-preview.1",
"com.unity.xr.arkit": "2.1.0-preview.1",
"com.unity.xr.arkit-face-tracking": "2.0.0-preview.1",
"com.unity.xr.legacyinputhelpers": "2.0.2",
"com.unity.modules.ai": "1.0.0",
"com.unity.modules.androidjni": "1.0.0",
"com.unity.modules.animation": "1.0.0",

44
ProjectSettings/EditorBuildSettings.asset


m_ObjectHideFlags: 0
serializedVersion: 2
m_Scenes:
- enabled: 1
path: Assets/Scenes/SampleScene.unity
guid: 99c9720ab356a0642a771bea13969a05
- enabled: 0
path: Assets/Scenes/ARWorldMap.unity
guid: 8d8902fd0b55449dcbf3572b49d6b1b1
- enabled: 0
path: Assets/Scenes/CameraImage.unity
guid: e769916924fd3814ab1d9474de816b22
path: Assets/Scenes/FeatheredPlaneScene.unity
path: Assets/Scenes/EnvironmentProbes.unity
guid: d568d188cadf141e38769dbabd3fe385
- enabled: 0
path: Assets/Scenes/FaceTracking/ARCoreFaceRegions.unity
guid: d1739ac106ca65e4b83528a440314bd9
- enabled: 0
path: Assets/Scenes/FaceTracking/ARKitFaceBlendShapes.unity
guid: e9280441e79e84bdbbf6b724880ae2d9
- enabled: 0
path: Assets/Scenes/FaceTracking/FaceMesh.unity
guid: 047514b96a5d44d6bb0acbfa06ace943
- enabled: 0
path: Assets/Scenes/FaceTracking/FacePose.unity
guid: d8b65509a10894e1dbb93c799ececfd9
- enabled: 0
path: Assets/Scenes/ImageTracking/ImageTracking.unity
guid: e0b018a3c3b5cfd4c8e316706ec0a18c
- enabled: 0
path: Assets/Scenes/LightEstimation.unity
guid: 2f0cbc82480584c258f99f0d9e4ba302
- enabled: 0
path: Assets/Scenes/Plane Detection/FeatheredPlanes.unity
- enabled: 0
path: Assets/Scenes/Plane Detection/TogglePlaneDetection.unity
guid: eb4bbb3a5e81acc41a903b1c5f1c827b
- enabled: 0
path: Assets/Scenes/Scale.unity
guid: 13ac91f677dc22f4ca320ef8ae727b68
- enabled: 0
path: Assets/Scenes/SimpleAR.unity
guid: 99c9720ab356a0642a771bea13969a05
- enabled: 0
path: Assets/Scenes/UX/SampleUXScene.unity
guid: 3b42d67a72bbc4004bf713db0e312326
m_configObjects:
com.unity.xr.arkit.PlayerSettings: {fileID: 11400000, guid: 2d5fb8e61571b4e3897f221189089fd6,
type: 2}

4
ProjectSettings/ProjectVersion.txt


m_EditorVersion: 2019.2.0a8
m_EditorVersionWithRevision: 2019.2.0a8 (18a4512f903f)
m_EditorVersion: 2019.2.0a11
m_EditorVersionWithRevision: 2019.2.0a11 (50bfd5f1a2f4)

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

7
Assets/Scenes/CameraImage.unity.meta


fileFormatVersion: 2
guid: e769916924fd3814ab1d9474de816b22
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

90
Assets/Scenes/ImageTracking/Images/QRCode.jpg

之前 之后
宽度: 300  |  高度: 300  |  大小: 23 KiB

88
Assets/Scenes/ImageTracking/Images/unitylogowhiteonblack.jpg

之前 之后
宽度: 512  |  高度: 512  |  大小: 18 KiB

114
Assets/Scripts/CameraConfigController.cs


using System.Collections.Generic;
using Unity.Collections;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.XR.ARFoundation;
/// <summary>
/// Populates a drop down UI element with all the supported
/// camera configurations and changes the active camera
/// configuration when the user changes the selection in the dropdown.
///
/// The camera configuration affects the resolution (and possibly framerate)
/// of the hardware camera during an AR session.
/// </summary>
[RequireComponent(typeof(Dropdown))]
public class CameraConfigController : MonoBehaviour
{
List<string> m_ConfigurationNames;
Dropdown m_Dropdown;
[SerializeField]
[Tooltip("The ARCameraManager which will produce frame events.")]
ARCameraManager m_CameraManager;
/// <summary>
/// Get or set the <c>ARCameraManager</c>.
/// </summary>
public ARCameraManager cameraManager
{
get { return m_CameraManager; }
set { m_CameraManager = value; }
}
/// <summary>
/// Callback invoked when <see cref="m_Dropdown"/> changes. This
/// lets us change the camera configuration when the user changes
/// the selection in the UI.
/// </summary>
/// <param name="dropdown">The <c>Dropdown</c> which changed.</param>
public void OnValueChanged(Dropdown dropdown)
{
if ((cameraManager == null) || (cameraManager.subsystem == null) || !cameraManager.subsystem.running)
{
return;
}
var configurationIndex = dropdown.value;
// Check that the value makes sense
using (var configurations = cameraManager.GetConfigurations(Allocator.Temp))
{
if (configurationIndex >= configurations.Length)
{
return;
}
// Get that configuration by index
var configuration = configurations[configurationIndex];
// Make it the active one
cameraManager.currentConfiguration = configuration;
}
}
void Awake()
{
m_Dropdown = GetComponent<Dropdown>();
m_Dropdown.ClearOptions();
m_ConfigurationNames = new List<string>();
}
void PopulateDropdown()
{
if ((cameraManager == null) || (cameraManager.subsystem == null) || !cameraManager.subsystem.running)
return;
// No configurations available probably means this feature
// isn't supported by the current device.
using (var configurations = cameraManager.GetConfigurations(Allocator.Temp))
{
if (!configurations.IsCreated || (configurations.Length <= 0))
{
return;
}
// There are two ways to enumerate the camera configurations.
// 1. Use a foreach to iterate over all the available configurations
foreach (var config in configurations)
{
m_ConfigurationNames.Add(config.ToString());
}
m_Dropdown.AddOptions(m_ConfigurationNames);
// 2. Use a normal for...loop
var currentConfig = cameraManager.currentConfiguration;
for (int i = 0; i < configurations.Length; ++i)
{
// Find the current configuration and update the drop down value
if (currentConfig == configurations[i])
{
m_Dropdown.value = i;
}
}
}
}
void Update()
{
if (m_ConfigurationNames.Count == 0)
PopulateDropdown();
}
}

11
Assets/Scripts/CameraConfigController.cs.meta


fileFormatVersion: 2
guid: 94b653a1faa6f4749ad83e77bcddfab4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

141
Assets/Scripts/TestCameraImage.cs


using System;
using Unity.Collections.LowLevel.Unsafe;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.XR.ARFoundation;
using UnityEngine.XR.ARSubsystems;
/// <summary>
/// This component tests getting the latest camera image
/// and converting it to RGBA format. If successful,
/// it displays the image on the screen as a RawImage
/// and also displays information about the image.
///
/// This is useful for computer vision applications where
/// you need to access the raw pixels from camera image
/// on the CPU.
///
/// This is different from the ARCameraBackground component, which
/// efficiently displays the camera image on the screen. If you
/// just want to blit the camera texture to the screen, use
/// the ARCameraBackground, or use Graphics.Blit to create
/// a GPU-friendly RenderTexture.
///
/// In this example, we get the camera image data on the CPU,
/// convert it to an RGBA format, then display it on the screen
/// as a RawImage texture to demonstrate it is working.
/// This is done as an example; do not use this technique simply
/// to render the camera image on screen.
/// </summary>
public class TestCameraImage : MonoBehaviour
{
[SerializeField]
[Tooltip("The ARCameraManager which will produce frame events.")]
ARCameraManager m_CameraManager;
/// <summary>
/// Get or set the <c>ARCameraManager</c>.
/// </summary>
public ARCameraManager cameraManager
{
get { return m_CameraManager; }
set { m_CameraManager = value; }
}
[SerializeField]
RawImage m_RawImage;
/// <summary>
/// The UI RawImage used to display the image on screen.
/// </summary>
public RawImage rawImage
{
get { return m_RawImage; }
set { m_RawImage = value; }
}
[SerializeField]
Text m_ImageInfo;
/// <summary>
/// The UI Text used to display information about the image on screen.
/// </summary>
public Text imageInfo
{
get { return m_ImageInfo; }
set { m_ImageInfo = value; }
}
void OnEnable()
{
if (m_CameraManager != null)
{
m_CameraManager.frameReceived += OnCameraFrameReceived;
}
}
void OnDisable()
{
if (m_CameraManager != null)
{
m_CameraManager.frameReceived -= OnCameraFrameReceived;
}
}
unsafe void OnCameraFrameReceived(ARCameraFrameEventArgs eventArgs)
{
// Attempt to get the latest camera image. If this method succeeds,
// it acquires a native resource that must be disposed (see below).
XRCameraImage image;
if (!cameraManager.TryGetLatestImage(out image))
{
return;
}
// Display some information about the camera image
m_ImageInfo.text = string.Format(
"Image info:\n\twidth: {0}\n\theight: {1}\n\tplaneCount: {2}\n\ttimestamp: {3}\n\tformat: {4}",
image.width, image.height, image.planeCount, image.timestamp, image.format);
// Once we have a valid XRCameraImage, we can access the individual image "planes"
// (the separate channels in the image). XRCameraImage.GetPlane provides
// low-overhead access to this data. This could then be passed to a
// computer vision algorithm. Here, we will convert the camera image
// to an RGBA texture and draw it on the screen.
// Choose an RGBA format.
// See XRCameraImage.FormatSupported for a complete list of supported formats.
var format = TextureFormat.RGBA32;
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.
// We can also get a sub rectangle, but we'll get the full image here.
var conversionParams = new XRCameraImageConversionParams(image, format, CameraImageTransformation.MirrorY);
// Texture2D allows us write directly to the raw texture data
// This allows us to do the conversion in-place without making any copies.
var rawTextureData = m_Texture.GetRawTextureData<byte>();
try
{
image.Convert(conversionParams, new IntPtr(rawTextureData.GetUnsafePtr()), rawTextureData.Length);
}
finally
{
// We must dispose of the XRCameraImage after we're finished
// with it to avoid leaking native resources.
image.Dispose();
}
// Apply the updated texture data to our texture
m_Texture.Apply();
// Set the RawImage's texture so we can visualize it.
m_RawImage.texture = m_Texture;
}
Texture2D m_Texture;
}

11
Assets/Scripts/TestCameraImage.cs.meta


fileFormatVersion: 2
guid: c6e58200659977344ad301e3a0f6e8d7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

18
Assets/Scenes/ImageTracking/Images/QRCode.asset


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 11f2715bf4e5ea943bc99337c8e80edf, type: 3}
m_Name: QRCode
m_EditorClassIdentifier:
m_GuidLow: 7013492382791275859
m_GuidHigh: 2402368290547687945
m_Width: 0.076
m_SpecifyWidth: 1

8
Assets/Scenes/ImageTracking/Images/QRCode.asset.meta


fileFormatVersion: 2
guid: 75b68e9ca7443e94897aee9514317bda
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

9
Assets/Scenes/ImageTracking/Images/QRCode.png

之前 之后

18
Assets/Scenes/ImageTracking/Images/Rafflesia.asset


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 11f2715bf4e5ea943bc99337c8e80edf, type: 3}
m_Name: Rafflesia
m_EditorClassIdentifier:
m_GuidLow: 3045804918016700000
m_GuidHigh: 12263723139385508072
m_Width: 0.28
m_SpecifyWidth: 1

8
Assets/Scenes/ImageTracking/Images/Rafflesia.asset.meta


fileFormatVersion: 2
guid: a7351be44527d304a85355f98dc6e294
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

18
Assets/Scenes/ImageTracking/Images/UnityLogoBlack.asset


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 11f2715bf4e5ea943bc99337c8e80edf, type: 3}
m_Name: UnityLogoBlack
m_EditorClassIdentifier:
m_GuidLow: 5833551047903198129
m_GuidHigh: 6063111697491653035
m_Width: 0.14
m_SpecifyWidth: 1

8
Assets/Scenes/ImageTracking/Images/UnityLogoBlack.asset.meta


fileFormatVersion: 2
guid: 80ce057f5368fdf44b72098a9085f0d6
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

48
Assets/Scenes/ImageTracking/Images/unitylogowhiteonblack.png

之前 之后

77
Assets/Scenes/ImageTracking/UnlitTexture.mat


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 6
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: UnlitTexture
m_Shader: {fileID: 10752, guid: 0000000000000000f000000000000000, type: 0}
m_ShaderKeywords:
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
stringTagMap: {}
disabledShaderPasses: []
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _BumpMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailAlbedoMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailMask:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailNormalMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _EmissionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MainTex:
m_Texture: {fileID: 10305, guid: 0000000000000000f000000000000000, type: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MetallicGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _OcclusionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _ParallaxMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- _BumpScale: 1
- _Cutoff: 0.5
- _DetailNormalMapScale: 1
- _DstBlend: 0
- _GlossMapScale: 1
- _Glossiness: 0.5
- _GlossyReflections: 1
- _Metallic: 0
- _Mode: 0
- _OcclusionStrength: 1
- _Parallax: 0.02
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _SrcBlend: 1
- _UVSec: 0
- _ZWrite: 1
m_Colors:
- _Color: {r: 1, g: 1, b: 1, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}

8
Assets/Scenes/ImageTracking/UnlitTexture.mat.meta


fileFormatVersion: 2
guid: b07d98b1f8b6877459a673ca44764071
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 2100000
userData:
assetBundleName:
assetBundleVariant:

/Assets/Scenes/ImageTracking/Images/unitylogowhiteonblack.png.meta → /Assets/Scenes/ImageTracking/Images/unitylogowhiteonblack.jpg.meta

/Assets/Scenes/ImageTracking/Images/QRCode.png.meta → /Assets/Scenes/ImageTracking/Images/QRCode.jpg.meta

正在加载...
取消
保存