-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Tangible Tracking Camera support
Added enabling the tangible camera and reading frames and pose Added the T5ImageCapture node to interface with the camera Update example.gd and example.csharp to demo new features
- Loading branch information
1 parent
a0207ea
commit 504a3cc
Showing
21 changed files
with
683 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using Godot; | ||
using System; | ||
|
||
public partial class T5ImageCaptureCS : Node3D | ||
{ | ||
public bool startCapture() | ||
{ | ||
return Call("start_capture").AsBool(); | ||
} | ||
|
||
public void stopCapture() | ||
{ | ||
Call("stop_capture"); | ||
} | ||
|
||
public bool acquireBuffer() | ||
{ | ||
return Call("acquire_buffer").AsBool(); | ||
} | ||
|
||
public void releaseBuffer() | ||
{ | ||
Call("release_buffer"); | ||
} | ||
|
||
public byte[] getImageData() | ||
{ | ||
return Call("get_image_data").As<byte[]>(); | ||
} | ||
|
||
public Transform3D getCameraTransform() | ||
{ | ||
return Call("get_camera_transform").As<Transform3D>(); | ||
} | ||
|
||
public Vector2I getImageSize() | ||
{ | ||
return Call("get_image_size").As<Vector2I>(); | ||
} | ||
|
||
public int getImageStride() | ||
{ | ||
return Call("get_image_stride").As<int>(); | ||
} | ||
|
||
public int getFrameIlluminationMode() | ||
{ | ||
return Call("get_frame_illumination_mode").As<int>(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<Project Sdk="Godot.NET.Sdk/4.2.1"> | ||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<TargetFramework Condition=" '$(GodotTargetPlatform)' == 'android' ">net7.0</TargetFramework> | ||
<TargetFramework Condition=" '$(GodotTargetPlatform)' == 'ios' ">net8.0</TargetFramework> | ||
<EnableDynamicLoading>true</EnableDynamicLoading> | ||
</PropertyGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
using Godot; | ||
using System; | ||
|
||
public partial class main : Node3D | ||
{ | ||
TextureRect cameraView; | ||
Image cameraImage; | ||
ImageTexture cameraTexture; | ||
T5ImageCaptureCS imageCapture; | ||
bool isCapturing = false; | ||
Vector2I currentImageSize = Vector2I.Zero; | ||
|
||
public override void _Ready() { | ||
cameraView = GetNode<TextureRect>("ScreenUI/CameraView"); | ||
} | ||
|
||
public override void _Process(double delta) | ||
{ | ||
if (imageCapture != null && isCapturing) | ||
{ | ||
if (imageCapture.acquireBuffer()) | ||
{ | ||
byte[] imageData = imageCapture.getImageData(); | ||
Vector2I imageSize = imageCapture.getImageSize(); | ||
|
||
if(cameraImage == null || imageSize != currentImageSize) | ||
{ | ||
cameraImage = Image.CreateFromData(imageSize.X, imageSize.Y, false, Image.Format.R8, imageData); | ||
cameraTexture = ImageTexture.CreateFromImage(cameraImage); | ||
cameraView.Texture = cameraTexture; | ||
currentImageSize = imageSize; | ||
} | ||
else | ||
{ | ||
cameraImage.SetData(imageSize.X, imageSize.Y, false, Image.Format.R8, imageData); | ||
cameraTexture.Update(cameraImage); | ||
} | ||
imageCapture.releaseBuffer(); | ||
} | ||
} | ||
} | ||
|
||
public override void _Input(InputEvent evt) | ||
{ | ||
if (evt.IsActionPressed("toggle_camera") && imageCapture != null) | ||
{ | ||
if (!isCapturing && imageCapture.startCapture()) | ||
{ | ||
isCapturing = true; | ||
cameraView.Visible = true; | ||
} | ||
else if (isCapturing) | ||
{ | ||
imageCapture.stopCapture(); | ||
isCapturing = false; | ||
cameraView.Visible = false; | ||
} | ||
} | ||
} | ||
|
||
private void _on_t_5_manager_xr_rig_was_added(SubViewport rig) | ||
{ | ||
var rigImageCapture = rig.GetNode<T5ImageCaptureCS>("Origin/T5ImageCapture"); | ||
if(imageCapture == null) { | ||
imageCapture = rigImageCapture; | ||
} | ||
} | ||
|
||
private void _on_t_5_manager_xr_rig_will_be_removed(SubViewport rig) | ||
{ | ||
var rigImageCapture = rig.GetNode<T5ImageCaptureCS>("Origin/T5ImageCapture"); | ||
if(imageCapture != null && imageCapture == rigImageCapture) { | ||
if(isCapturing) | ||
{ | ||
imageCapture.stopCapture(); | ||
isCapturing = false; | ||
cameraView.Visible = false; | ||
} | ||
imageCapture = null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,55 @@ | ||
extends Node3D | ||
|
||
func _on_t5_manager_glasses_scene_was_added(glasses): | ||
print("Scene ", glasses.name, " added") | ||
var image_capture: T5ImageCapture | ||
var is_capturing := false | ||
var image_size: Vector2i | ||
var camera_image: Image | ||
@onready var camera_view: TextureRect = $ScreenUI/CameraView | ||
|
||
func _on_t5_manager_glasses_scene_will_be_removed(glasses): | ||
print("Scene ", glasses.name, " removed") | ||
# Grab the T5ImageCapture out of the xr rig | ||
func _on_t_5_manager_xr_rig_was_added(xr_rig: T5XRRig): | ||
var new_image_capture = xr_rig.get_image_capture() | ||
if not image_capture and new_image_capture: | ||
image_capture = new_image_capture | ||
|
||
func _on_t_5_manager_xr_rig_will_be_removed(xr_rig): | ||
var old_image_capture = xr_rig.get_image_capture() | ||
if image_capture and image_capture == old_image_capture: | ||
if is_capturing: | ||
image_capture.stop_capture() | ||
is_capturing = false | ||
camera_view.visible = false | ||
image_capture = null | ||
|
||
# Toggle the camera on and off | ||
func _input(event): | ||
if image_capture == null: | ||
return | ||
if not event.is_action_pressed("toggle_camera"): | ||
return | ||
if not is_capturing and image_capture.start_capture(): | ||
is_capturing = true | ||
camera_view.visible = true | ||
else: | ||
image_capture.stop_capture() | ||
is_capturing = false | ||
camera_view.visible = false | ||
|
||
func _process(_delta): | ||
if not is_capturing: | ||
return | ||
# Test to see if a image buffer is available | ||
if image_capture.acquire_buffer(): | ||
# get the image data | ||
var buffer := image_capture.get_image_data() | ||
# Get the size | ||
var new_size = image_capture.get_image_size() | ||
# If is the first time of the size has changed | ||
if camera_image == null or image_size != new_size: | ||
image_size = new_size | ||
camera_image = Image.create_from_data(image_size.x, image_size.y, false, Image.FORMAT_R8, buffer) | ||
camera_view.texture = ImageTexture.create_from_image(camera_image) | ||
else: | ||
camera_image.set_data(image_size.x, image_size.y, false, Image.FORMAT_R8, buffer) | ||
camera_view.texture.update(camera_image) | ||
image_capture.release_buffer() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.