Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
avvy
mobile-app
Commits
b2446d05
Commit
b2446d05
authored
3 years ago
by
Ylly
Browse files
Options
Download
Email Patches
Plain Diff
Add ArCameraToImageUtil
parent
d0549b37
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Assets/AvvyLand/Scripts/Utils/Debug/ArCameraToImageUtil.cs
+65
-0
Assets/AvvyLand/Scripts/Utils/Debug/ArCameraToImageUtil.cs
Assets/AvvyLand/Scripts/Utils/Debug/ArCameraToImageUtil.cs.meta
+11
-0
.../AvvyLand/Scripts/Utils/Debug/ArCameraToImageUtil.cs.meta
with
76 additions
and
0 deletions
+76
-0
Assets/AvvyLand/Scripts/Utils/Debug/ArCameraToImageUtil.cs
0 → 100644
View file @
b2446d05
using
System
;
using
Unity.Collections
;
using
Unity.Collections.LowLevel.Unsafe
;
using
UnityEngine
;
using
UnityEngine.UI
;
using
UnityEngine.XR.ARFoundation
;
using
UnityEngine.XR.ARSubsystems
;
namespace
AvvyLand.Scripts.Utils.Debug
{
public
class
ArCameraToImageUtil
:
MonoBehaviour
{
[
SerializeField
]
private
RawImage
RawImage
;
private
ARCameraManager
CameraManager
;
private
Texture2D
RGB_Texture
;
private
void
Update
()
{
FindCameraManager
();
}
private
void
FindCameraManager
()
{
if
(
CameraManager
!=
null
)
return
;
CameraManager
=
GameObject
.
FindObjectOfType
<
ARCameraManager
>();
CameraManager
.
frameReceived
+=
(
x
)
=>
CameraFrameReceived
();
}
private
unsafe
void
CameraFrameReceived
()
{
if
(!
CameraManager
.
TryAcquireLatestCpuImage
(
out
XRCpuImage
image
))
return
;
var
conversionParams
=
new
XRCpuImage
.
ConversionParams
{
inputRect
=
new
RectInt
(
0
,
0
,
image
.
width
,
image
.
height
),
outputDimensions
=
new
Vector2Int
(
244
,
244
),
outputFormat
=
TextureFormat
.
RGBA32
,
transformation
=
XRCpuImage
.
Transformation
.
MirrorY
};
int
size
=
image
.
GetConvertedDataSize
(
conversionParams
);
var
buffer
=
new
NativeArray
<
byte
>(
size
,
Allocator
.
Temp
);
image
.
Convert
(
conversionParams
,
new
IntPtr
(
buffer
.
GetUnsafePtr
()),
buffer
.
Length
);
var
x
=
conversionParams
.
outputDimensions
.
x
;
var
y
=
conversionParams
.
outputDimensions
.
y
;
// if (RGB_Texture == null)
{
RGB_Texture
=
new
Texture2D
(
x
,
y
,
conversionParams
.
outputFormat
,
false
);
RGB_Texture
.
LoadRawTextureData
(
buffer
);
RGB_Texture
.
Apply
();
}
image
.
Dispose
();
buffer
.
Dispose
();
RawImage
.
texture
=
RGB_Texture
;
}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Assets/AvvyLand/Scripts/Utils/Debug/ArCameraToImageUtil.cs.meta
0 → 100644
View file @
b2446d05
fileFormatVersion: 2
guid: 68bb9db3ad2138d4fbf74f3ee6248bf1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help