Init
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 491cc602739859c45a1c57ecacee1c75
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fc18359004abe7c4e87aae3065f3c2d4
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Binary file not shown.
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 685f95f93c2d03c46afbc63a27fdb64c
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 112000000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Binary file not shown.
@@ -0,0 +1,130 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8529bcf1fa2b8f740af2243539e6288d
|
||||
TextureImporter:
|
||||
internalIDToNameTable: []
|
||||
externalObjects: {}
|
||||
serializedVersion: 13
|
||||
mipmaps:
|
||||
mipMapMode: 0
|
||||
enableMipMap: 1
|
||||
sRGBTexture: 1
|
||||
linearTexture: 0
|
||||
fadeOut: 0
|
||||
borderMipMap: 0
|
||||
mipMapsPreserveCoverage: 0
|
||||
alphaTestReferenceValue: 0.5
|
||||
mipMapFadeDistanceStart: 1
|
||||
mipMapFadeDistanceEnd: 3
|
||||
bumpmap:
|
||||
convertToNormalMap: 0
|
||||
externalNormalMap: 0
|
||||
heightScale: 0.25
|
||||
normalMapFilter: 0
|
||||
flipGreenChannel: 0
|
||||
isReadable: 0
|
||||
streamingMipmaps: 0
|
||||
streamingMipmapsPriority: 0
|
||||
vTOnly: 0
|
||||
ignoreMipmapLimit: 0
|
||||
grayScaleToAlpha: 0
|
||||
generateCubemap: 6
|
||||
cubemapConvolution: 1
|
||||
seamlessCubemap: 1
|
||||
textureFormat: 1
|
||||
maxTextureSize: 2048
|
||||
textureSettings:
|
||||
serializedVersion: 2
|
||||
filterMode: 2
|
||||
aniso: 0
|
||||
mipBias: 0
|
||||
wrapU: 1
|
||||
wrapV: 1
|
||||
wrapW: 1
|
||||
nPOTScale: 1
|
||||
lightmap: 0
|
||||
compressionQuality: 50
|
||||
spriteMode: 0
|
||||
spriteExtrude: 1
|
||||
spriteMeshType: 1
|
||||
alignment: 0
|
||||
spritePivot: {x: 0.5, y: 0.5}
|
||||
spritePixelsToUnits: 100
|
||||
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
|
||||
spriteGenerateFallbackPhysicsShape: 1
|
||||
alphaUsage: 1
|
||||
alphaIsTransparency: 0
|
||||
spriteTessellationDetail: -1
|
||||
textureType: 0
|
||||
textureShape: 2
|
||||
singleChannelComponent: 0
|
||||
flipbookRows: 1
|
||||
flipbookColumns: 1
|
||||
maxTextureSizeSet: 0
|
||||
compressionQualitySet: 0
|
||||
textureFormatSet: 0
|
||||
ignorePngGamma: 0
|
||||
applyGammaDecoding: 0
|
||||
swizzle: 50462976
|
||||
cookieLightType: 0
|
||||
platformSettings:
|
||||
- serializedVersion: 4
|
||||
buildTarget: DefaultTexturePlatform
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 100
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
ignorePlatformSupport: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
- serializedVersion: 4
|
||||
buildTarget: Standalone
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
ignorePlatformSupport: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
- serializedVersion: 4
|
||||
buildTarget: Android
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
ignorePlatformSupport: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
spriteSheet:
|
||||
serializedVersion: 2
|
||||
sprites: []
|
||||
outline: []
|
||||
customData:
|
||||
physicsShape: []
|
||||
bones: []
|
||||
spriteID:
|
||||
internalID: 0
|
||||
vertices: []
|
||||
indices:
|
||||
edges: []
|
||||
weights: []
|
||||
secondaryTextures: []
|
||||
spriteCustomMetadata:
|
||||
entries: []
|
||||
nameFileIdTable: {}
|
||||
mipmapLimitGroupName:
|
||||
pSDRemoveMatte: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,242 @@
|
||||
#if PICO_OPENXR_SDK
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using Unity.XR.OpenXR.Features.PICOSupport;
|
||||
using Unity.XR.PICO.TOBSupport;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
#if UNITY_XR_COMPOSITIONLAYERS
|
||||
using Unity.XR.CompositionLayers;
|
||||
using Unity.XR.OpenXR.Features.PICOSupport;
|
||||
using UnityEngine.XR.OpenXR.CompositionLayers;
|
||||
#endif
|
||||
public class EnterpriseAPI_OpenXR : MonoBehaviour
|
||||
{
|
||||
private string tag = "CaptureLib ----";
|
||||
#if UNITY_XR_COMPOSITIONLAYERS
|
||||
private CompositionLayer _overlay = null;
|
||||
#endif
|
||||
private PXRCaptureRenderMode Mode = PXRCaptureRenderMode.PXRCapture_RenderMode_LEFT;
|
||||
byte[] imgByte ;
|
||||
private int width=2048;
|
||||
private int height=1536;
|
||||
public Material videoMaterial;
|
||||
public Transform FrameTarget;
|
||||
public Transform RenderTarget;
|
||||
public Text CanshuText;
|
||||
public Toggle showtime;
|
||||
public Text showtimeText;
|
||||
private bool isRuning=false;
|
||||
// 将视频帧转换为 Unity 纹理
|
||||
Texture2D texture;
|
||||
public Text fpsText;
|
||||
bool camera_raw_data=true;
|
||||
private void Awake()
|
||||
{
|
||||
Debug.Log($"{tag} Awake ");
|
||||
PassthroughFeature.EnableVideoSeeThrough=true;
|
||||
#if UNITY_XR_COMPOSITIONLAYERS
|
||||
_overlay = GetComponent<CompositionLayer>();
|
||||
if (_overlay == null)
|
||||
{
|
||||
_overlay = gameObject.AddComponent<CompositionLayer>();
|
||||
}
|
||||
#endif
|
||||
imgByte = new byte[width*height*4];
|
||||
texture = new Texture2D((int)width, (int)height, TextureFormat.RGBA32, false);
|
||||
videoMaterial.SetTexture("_MainTex", texture);
|
||||
|
||||
|
||||
Dictionary<string, string> cameraParams1 = new Dictionary<string, string>();
|
||||
cameraParams1.Add(PXRCapture.KEY_ENABLE_MVHEVC, PXRCapture.VALUE_FALSE);
|
||||
cameraParams1.Add(PXRCapture.KEY_VIDEO_FPS, "30");
|
||||
cameraParams1.Add(PXRCapture.KEY_OUTPUT_CAMERA_RAW_DATA, camera_raw_data?PXRCapture.VALUE_TRUE:PXRCapture.VALUE_FALSE);
|
||||
|
||||
PXR_Enterprise.Configurefor4U(cameraParams1);
|
||||
|
||||
Dictionary<string, string> cameraParams = new Dictionary<string, string>();
|
||||
cameraParams.Add(PXRCapture.KEY_MCTF, PXRCapture.VALUE_TRUE);
|
||||
cameraParams.Add(PXRCapture.KEY_EIS, PXRCapture.VALUE_FALSE);
|
||||
cameraParams.Add(PXRCapture.KEY_MFNR, PXRCapture.VALUE_TRUE);
|
||||
|
||||
PXR_Enterprise.OpenCameraAsyncfor4U(ret =>
|
||||
{
|
||||
Debug.Log($"{tag} OpenCameraAsync ret= {ret}");
|
||||
},cameraParams);
|
||||
|
||||
Invoke(nameof(getCameraParameters), 1f);
|
||||
|
||||
}
|
||||
public void SetTrackingMode(int listChoice)
|
||||
{
|
||||
Debug.Log($"{tag} SetMode ret= {listChoice}");
|
||||
// if (listChoice > 0)
|
||||
{
|
||||
switch (listChoice)
|
||||
{
|
||||
case 0:
|
||||
Mode = PXRCaptureRenderMode.PXRCapture_RenderMode_LEFT;
|
||||
break;
|
||||
case 1:
|
||||
Mode = PXRCaptureRenderMode.PXRCapture_RenderMode_RIGHT;
|
||||
break;
|
||||
case 2:
|
||||
Mode = PXRCaptureRenderMode.PXRCapture_RenderMode_3D;
|
||||
break;
|
||||
case 3:
|
||||
Mode = PXRCaptureRenderMode.PXRCapture_RenderMode_Interlace;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
float outputFovHorizontal=76.35f;
|
||||
float outputFovVertical=61.05f;
|
||||
public void getCameraParameters()
|
||||
{
|
||||
Debug.Log($"{tag} getCamera ");
|
||||
double[] CameraIntrinsics=PXR_Enterprise.GetCameraIntrinsicsfor4U(width, height, outputFovHorizontal, outputFovVertical);
|
||||
PXR_Enterprise.GetCameraExtrinsicsfor4U(out Matrix4x4 leftExtrinsics, out Matrix4x4 rightExtrinsics);
|
||||
Debug.Log($"getCamera-- GetCameraIntrinsics:[{CameraIntrinsics[0]},{CameraIntrinsics[1]},{CameraIntrinsics[2]},{CameraIntrinsics[3]}]");
|
||||
Debug.Log(tag+"getCamera-- GetCameraExtrinsics leftExtrinsics :\n"+leftExtrinsics);
|
||||
Debug.Log(tag+"getCamera-- GetCameraExtrinsics rightExtrinsics :\n"+rightExtrinsics);
|
||||
|
||||
RGBCameraParamsNew param = PXR_Enterprise.GetCameraParametersNewfor4U(width, height);
|
||||
// Debug.Log($"getCamera GetCameraIntrinsics:[{param.cx},{param.cy},{param.fx},{param.fy}]");
|
||||
// Debug.Log($"getCamera GetCameraExtrinsics leftExtrinsics::[{param.l_pos} ------ {param.l_rot}]");
|
||||
// Debug.Log($"getCamera GetCameraExtrinsics rightExtrinsics::[{param.r_pos} ------ {param.r_rot}]");
|
||||
CanshuText.text =$"内参::[fx,fy,cx,cy]=[{param.fx},{param.fy},{param.cx},{param.cy}]\n"+ $"外参::L=[{param.l_pos},{param.l_rot}]\n"+$" R=[{param.r_pos},{param.r_rot}]";
|
||||
}
|
||||
public void StartPreview()
|
||||
{
|
||||
Debug.Log($"{tag} StartPreview ");
|
||||
FrameTarget.position = new Vector3(0,0,0);
|
||||
FrameTarget.rotation = Quaternion.Euler(0,0,0);
|
||||
RenderTarget.position = new Vector3(0,0,0);
|
||||
RenderTarget.rotation = Quaternion.Euler(0,0,0);
|
||||
#if UNITY_XR_COMPOSITIONLAYERS
|
||||
_overlay.enabled = true;
|
||||
StartCoroutine(_StartPreview());
|
||||
#endif
|
||||
}
|
||||
|
||||
#if UNITY_XR_COMPOSITIONLAYERS
|
||||
private IEnumerator _StartPreview()
|
||||
{
|
||||
IntPtr surface = IntPtr.Zero;
|
||||
yield return new WaitUntil(() =>
|
||||
{
|
||||
surface = OpenXRLayerUtility.GetLayerAndroidSurfaceObject(_overlay.GetInstanceID());
|
||||
PXR_Enterprise.StartPreviewfor4U(surface,Mode);
|
||||
return (surface != IntPtr.Zero);
|
||||
});
|
||||
}
|
||||
#endif
|
||||
|
||||
public float showTime = 1f;
|
||||
|
||||
private int count = 0;
|
||||
private float deltaTime = 0f;
|
||||
public void StartGetImageData()
|
||||
{
|
||||
Debug.Log($"{tag} StartGetImageData ");
|
||||
#if UNITY_XR_COMPOSITIONLAYERS
|
||||
_overlay.enabled = false;
|
||||
#endif
|
||||
IntPtr data=Marshal.UnsafeAddrOfPinnedArrayElement(imgByte,0);
|
||||
PXR_Enterprise.SetCameraFrameBufferfor4U(width,height,ref data, (Frame frame) =>
|
||||
{
|
||||
// Debug.Log($"{tag} sensorState position:[{frame.sensorState.globalPose.position.x},{frame.sensorState.globalPose.position.y},{frame.sensorState.globalPose.position.z}]," +
|
||||
// $" orientation:[{frame.sensorState.globalPose.orientation.x},{frame.sensorState.globalPose.orientation.y},{frame.sensorState.globalPose.orientation.z},{frame.sensorState.globalPose.orientation.w}] ");
|
||||
// FrameTarget.position=frame.pose.position;
|
||||
// FrameTarget.rotation = frame.pose.rotation;
|
||||
// FrameTarget.position = new Vector3(frame.pose.position.x, frame.pose.position.y, -frame.pose.position.z);
|
||||
// FrameTarget.rotation = new Quaternion(frame.pose.rotation.x, frame.pose.rotation.y, -frame.pose.rotation.z, -frame.pose.rotation.w);
|
||||
FrameTarget.position = frame.pose.position;
|
||||
FrameTarget.rotation = frame.pose.rotation;
|
||||
if (showtime.isOn)
|
||||
{
|
||||
showtimeText.text = frame.timestamp+"";
|
||||
}
|
||||
else
|
||||
{
|
||||
showtimeText.text = frame.timestamp+"";
|
||||
texture.LoadRawTextureData(imgByte);
|
||||
texture.Apply();
|
||||
}
|
||||
|
||||
Debug.Log($"{tag} imageAvailable ");
|
||||
Debug.Log($"{tag} onImageAvailable cameraFramePredictedDisplayTime = "+frame.timestamp +" Time.deltaTime:"+Time.deltaTime);
|
||||
Debug.Log($"{tag} onImageAvailable size = "+frame.datasize);
|
||||
count++;
|
||||
});
|
||||
Debug.Log($"{tag} StartGetImageData Mode= {Mode}");
|
||||
bool ret=PXR_Enterprise.StartGetImageDatafor4U(Mode, width, height);
|
||||
isRuning=true;
|
||||
Debug.Log($"{tag} StartGetImageData ret= {ret}");
|
||||
}
|
||||
|
||||
|
||||
public void Release()
|
||||
{
|
||||
PXR_Enterprise.CloseCamerafor4U();
|
||||
isRuning=false;
|
||||
}
|
||||
|
||||
private double time = 0;
|
||||
private SensorState a;
|
||||
private void Update()
|
||||
{
|
||||
deltaTime += Time.deltaTime;
|
||||
if (deltaTime >= showTime) {
|
||||
if (count>0)
|
||||
{
|
||||
float fps = count / deltaTime;
|
||||
float milliSecond = deltaTime * 1000 / count;
|
||||
string strFpsInfo = string.Format("当前每帧渲染间隔:{0:0.0} ms ({1:0.} 帧每秒)", milliSecond, fps);
|
||||
fpsText.text = strFpsInfo;
|
||||
}
|
||||
count = 0;
|
||||
deltaTime = 0f;
|
||||
}
|
||||
if (reopen)
|
||||
{
|
||||
reopen = false;
|
||||
PXR_Enterprise.StartGetImageDatafor4U(Mode, width, height);
|
||||
isRuning=true;
|
||||
}
|
||||
|
||||
|
||||
time= PXR_Enterprise.GetPredictedDisplayTime();
|
||||
a=PXR_Enterprise.GetPredictedMainSensorState(time);
|
||||
RenderTarget.position = a.pose.position;
|
||||
RenderTarget.rotation = a.pose.rotation;
|
||||
// RenderTarget.position = new Vector3(a.pose.position.x, a.pose.position.y, -a.pose.position.z);
|
||||
// RenderTarget.rotation = new Quaternion(a.pose.rotation.x, a.pose.rotation.y, -a.pose.rotation.z, -a.pose.rotation.w);
|
||||
}
|
||||
static bool reopen = false;
|
||||
private void OnApplicationPause(bool pauseStatus)
|
||||
{
|
||||
if (isRuning)
|
||||
{
|
||||
// PXR_Enterprise.SetRunningState(pauseStatus);
|
||||
if (pauseStatus)
|
||||
{
|
||||
PXR_Enterprise.CloseCamerafor4U();
|
||||
}
|
||||
else
|
||||
{
|
||||
PXR_Enterprise.OpenCameraAsyncfor4U(ret =>
|
||||
{
|
||||
Debug.Log($"{tag} OpenCameraAsync reopen= {ret}");
|
||||
reopen = ret;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ed1e10c5fb5ae544595d9c223445b3c9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user