forked from GodotVR/TiltFiveGodot4
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'camera_support' into ahead_of_godotvr
- Loading branch information
Showing
20 changed files
with
681 additions
and
13 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,76 @@ | ||
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) | ||
{ | ||
imageCapture = rig.GetNode<T5ImageCaptureCS>("Origin/T5ImageCapture"); | ||
} | ||
|
||
private void _on_t_5_manager_xr_rig_will_be_removed(SubViewport rig) | ||
{ | ||
if(imageCapture != null && 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,9 +1,55 @@ | ||
extends Node3D | ||
|
||
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_xr_rig_was_added(xr_rig): | ||
print("Scene for glasses ", xr_rig.get_glasses_id(), " added") | ||
# 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 _on_t5_manager_xr_rig_will_be_removed(xr_rig): | ||
print("Scene for glasses ", xr_rig.get_glasses_id(), " removed") | ||
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
Oops, something went wrong.