Skip to content

Commit

Permalink
Merge pull request #19 from elmajime/Adding_camera_feed_and_planes_de…
Browse files Browse the repository at this point in the history
…tection

Added camera feed and plane detection (both vertical and horizontal)
  • Loading branch information
BastiaanOlij authored Nov 19, 2024
2 parents 835662e + c6ab813 commit 1509a01
Show file tree
Hide file tree
Showing 36 changed files with 315,396 additions and 680 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build-on-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ jobs:
- name: Create libgodot-cpp Android templates
run: |
cd $GITHUB_WORKSPACE/repo/godot-cpp
scons platform=android target=template_debug arch=arm64
scons platform=android target=template_release arch=arm64
scons platform=android target=template_debug arch=arm64 custom_api_file=../thirdparty/godot_cpp_extension_api/extension_api.json
scons platform=android target=template_release arch=arm64 custom_api_file=../thirdparty/godot_cpp_extension_api/extension_api.json
cd $GITHUB_WORKSPACE
- name: Assemble the plugin
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@ google-services.json

# Android Profiling
*.hprof

# IDE
.vscode
35 changes: 0 additions & 35 deletions .vscode/tasks.json

This file was deleted.

3 changes: 3 additions & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Contributors
This plugin has mostly been developed by:
- [Bastiaan Olij](https://github.com/BastiaanOlij)
- [Fredia Huya-Kouadio](https://github.com/m4gr3d)
- [Patrick Exner](https://github.com/paddy-exe)
- [Maxime Chambefort](https://github.com/elmajime)
- [Luca Junge](https://github.com/LucaJunge)

Other people who have helped out by submitting fixes, enhancements, etc are:
- help out to get your name listed here!
2 changes: 1 addition & 1 deletion godot-cpp
Submodule godot-cpp updated 62 files
+1 −1 .github/ISSUE_TEMPLATE/bug_report.yml
+4 −5 .github/actions/godot-cache-restore/action.yml
+17 −0 .github/actions/godot-cache-save/action.yml
+10 −4 .github/workflows/ci.yml
+12 −0 CMakeLists.txt
+14 −12 README.md
+302 −72 binding_generator.py
+40,645 −20,146 gdextension/extension_api.json
+377 −37 gdextension/gdextension_interface.h
+4 −4 include/godot_cpp/classes/ref.hpp
+75 −24 include/godot_cpp/classes/wrapped.hpp
+17 −5 include/godot_cpp/core/class_db.hpp
+6 −3 include/godot_cpp/core/memory.hpp
+1 −0 include/godot_cpp/core/method_ptrcall.hpp
+2 −0 include/godot_cpp/core/object.hpp
+11 −0 include/godot_cpp/core/property_info.hpp
+20 −10 include/godot_cpp/core/type_info.hpp
+19 −3 include/godot_cpp/godot.hpp
+42 −24 include/godot_cpp/templates/list.hpp
+4 −0 include/godot_cpp/templates/local_vector.hpp
+1 −1 include/godot_cpp/templates/safe_refcount.hpp
+1 −1 include/godot_cpp/variant/aabb.hpp
+1 −0 include/godot_cpp/variant/callable_custom.hpp
+25 −0 include/godot_cpp/variant/callable_method_pointer.hpp
+5 −9 include/godot_cpp/variant/rect2.hpp
+5 −9 include/godot_cpp/variant/rect2i.hpp
+10 −0 include/godot_cpp/variant/typed_array.hpp
+3 −0 include/godot_cpp/variant/variant.hpp
+10 −0 include/godot_cpp/variant/vector2.hpp
+14 −0 include/godot_cpp/variant/vector2i.hpp
+11 −0 include/godot_cpp/variant/vector3.hpp
+22 −0 include/godot_cpp/variant/vector3i.hpp
+11 −0 include/godot_cpp/variant/vector4.hpp
+22 −0 include/godot_cpp/variant/vector4i.hpp
+9 −0 src/classes/low_level.cpp
+17 −7 src/classes/wrapped.cpp
+41 −0 src/core/class_db.cpp
+76 −6 src/godot.cpp
+16 −2 src/variant/callable_custom.cpp
+11 −2 src/variant/callable_method_pointer.cpp
+4 −4 src/variant/char_string.cpp
+19 −0 src/variant/packed_arrays.cpp
+9 −0 src/variant/variant.cpp
+12 −0 src/variant/vector2.cpp
+26 −0 src/variant/vector2i.cpp
+19 −0 src/variant/vector3.cpp
+21 −0 src/variant/vector3i.cpp
+21 −0 src/variant/vector4.cpp
+24 −0 src/variant/vector4i.cpp
+4 −0 test/SConstruct
+25 −0 test/doc_classes/Example.xml
+5 −0 test/project/example.gd
+4 −2 test/project/example.gdextension
+20 −1 test/project/main.gd
+3 −1 test/project/main.tscn
+1 −1 test/project/project.godot
+62 −1 test/src/example.cpp
+28 −0 test/src/example.h
+1 −0 test/src/register_types.cpp
+54 −1 tools/godotcpp.py
+3 −13 tools/ios.py
+9 −4 tools/web.py
Binary file added plugin/demo/Godot_ARCoreExample.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions plugin/demo/MeshInstance3D.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
extends MeshInstance3D


# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
rotate(Vector3(0, 0, 1), delta)
14 changes: 7 additions & 7 deletions plugin/demo/export_presets.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ custom_features=""
export_filter="all_resources"
include_filter=""
exclude_filter=""
export_path="../../../../../Downloads/arcore_demo.apk"
export_path="./GDExtension Android Plugin Demo.apk"
encryption_include_filters=""
encryption_exclude_filters=""
encrypt_pck=false
Expand All @@ -20,16 +20,16 @@ custom_template/debug=""
custom_template/release=""
gradle_build/use_gradle_build=true
gradle_build/export_format=0
gradle_build/min_sdk=""
gradle_build/target_sdk=""
gradle_build/min_sdk="31"
gradle_build/target_sdk="31"
architectures/armeabi-v7a=false
architectures/arm64-v8a=true
architectures/x86=false
architectures/x86_64=false
version/code=1
version/name=""
package/unique_name="org.godotengine.android.arcore.plugin"
package/name="ARCore Demo"
package/unique_name="org.godotengine.plugin.android.gdextension.arcore.Godot_ARCore_example"
package/name=""
package/signed=true
package/app_category=2
package/retain_data_on_uninstall=false
Expand Down Expand Up @@ -86,10 +86,10 @@ permissions/broadcast_sticky=false
permissions/broadcast_wap_push=false
permissions/call_phone=false
permissions/call_privileged=false
permissions/camera=false
permissions/camera=true
permissions/capture_audio_output=false
permissions/capture_secure_video_output=false
permissions/capture_video_output=false
permissions/capture_video_output=true
permissions/change_component_enabled_state=false
permissions/change_configuration=false
permissions/change_network_state=false
Expand Down
41 changes: 9 additions & 32 deletions plugin/demo/main.gd
Original file line number Diff line number Diff line change
@@ -1,41 +1,18 @@
extends Node3D
extends Node2D

# TODO: Update to match your plugin's name
var _plugin_name = "ARCorePlugin"
var ARCorePlugin
var _android_plugin

var simultaneous_scene = preload("res://main3D.tscn").instantiate()

func _ready():
if Engine.has_singleton(_plugin_name):
ARCorePlugin = Engine.get_singleton(_plugin_name)

# This sets up access to the environment and godot classes
ARCorePlugin.initializeEnvironment()
_android_plugin = Engine.get_singleton(_plugin_name)
else:
printerr("Couldn't find plugin " + _plugin_name)

func _process(delta):
# Display the XRCamera position we get from ARCore
# print($XROrigin3D.position)
# print($XROrigin3D/XRCamera3D.fov)
$CanvasLayer/Control/VBoxContainer/MarginContainer2/VBoxContainer/CameraPositionLabel.text = "XRCamera3D.position: " + str($XROrigin3D/XRCamera3D.position)
$CanvasLayer/Control/VBoxContainer/MarginContainer2/VBoxContainer/TrackingState.text = "Tracking State: " + get_tracking_state()

func _on_start_ar_button_pressed():
print("ARCoreInterfaceInstance")

# This should be named "ARCoreInterface" but there is a name clash with the registered class "ARCoreInterface"
ARCoreInterfaceInstance.start()

func get_tracking_state() -> String:
var status = ARCoreInterfaceInstance.get_tracking_status()

if status == XRInterface.XR_NOT_TRACKING:
return "Not Tracking"
elif status == XRInterface.XR_NORMAL_TRACKING:
return "Normal Tracking"
else:
return "Unknown Tracking"
#if ARCoreInterfaceInstance.get_tracking_status() == 0:
# return "Not Tracking"
#else:
# return "Unknown State"
func _on_Button_pressed():
if _android_plugin:
# TODO: Update to match your plugin's API
get_tree().root.add_child(simultaneous_scene)
139 changes: 13 additions & 126 deletions plugin/demo/main.tscn
Original file line number Diff line number Diff line change
@@ -1,132 +1,19 @@
[gd_scene load_steps=10 format=3 uid="uid://cg3hylang5fxn"]
[gd_scene load_steps=2 format=3 uid="uid://cg3hylang5fxn"]

[ext_resource type="Script" path="res://main.gd" id="1_j0gfq"]

[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_rr52s"]
bg_color = Color(0.2655, 0.317775, 0.45, 1)
border_width_left = 4
border_width_top = 4
border_width_right = 4
border_width_bottom = 4
border_color = Color(0.206182, 0.248662, 0.360116, 1)
corner_radius_top_left = 20
corner_radius_top_right = 20
corner_radius_bottom_right = 20
corner_radius_bottom_left = 20

[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_x8ygb"]
albedo_color = Color(0, 0, 1, 1)

[sub_resource type="BoxMesh" id="BoxMesh_wukjl"]
material = SubResource("StandardMaterial3D_x8ygb")
size = Vector3(0.4, 0.4, 0.4)

[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_trvgj"]
albedo_color = Color(1, 0, 0, 1)

[sub_resource type="SphereMesh" id="SphereMesh_yvi2r"]
material = SubResource("StandardMaterial3D_trvgj")
radius = 0.05
height = 0.1

[sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_lvyi5"]
sky_horizon_color = Color(0.64625, 0.65575, 0.67075, 1)
ground_horizon_color = Color(0.64625, 0.65575, 0.67075, 1)

[sub_resource type="Sky" id="Sky_vwrey"]
sky_material = SubResource("ProceduralSkyMaterial_lvyi5")

[sub_resource type="Environment" id="Environment_603g6"]
background_mode = 2
sky = SubResource("Sky_vwrey")
tonemap_mode = 2

[node name="Main" type="Node3D"]
[node name="Main" type="Node2D"]
script = ExtResource("1_j0gfq")

[node name="CanvasLayer" type="CanvasLayer" parent="."]

[node name="Control" type="Control" parent="CanvasLayer"]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2

[node name="VBoxContainer" type="VBoxContainer" parent="CanvasLayer/Control"]
layout_mode = 1
anchors_preset = 15
[node name="Button" type="Button" parent="."]
anchors_preset = 14
anchor_top = 0.5
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2

[node name="MarginContainer2" type="MarginContainer" parent="CanvasLayer/Control/VBoxContainer"]
layout_mode = 2
theme_override_constants/margin_left = 50
theme_override_constants/margin_top = 100
theme_override_constants/margin_right = 50
theme_override_constants/margin_bottom = 50

[node name="VBoxContainer" type="VBoxContainer" parent="CanvasLayer/Control/VBoxContainer/MarginContainer2"]
layout_mode = 2

[node name="CameraPositionLabel" type="Label" parent="CanvasLayer/Control/VBoxContainer/MarginContainer2/VBoxContainer"]
layout_mode = 2
theme_override_font_sizes/font_size = 30
text = "XRCamera.position: [0, 0, 0]"

[node name="TrackingState" type="Label" parent="CanvasLayer/Control/VBoxContainer/MarginContainer2/VBoxContainer"]
layout_mode = 2
theme_override_font_sizes/font_size = 30
text = "Tracking State: Not tracking"

[node name="Spacer" type="Control" parent="CanvasLayer/Control/VBoxContainer"]
layout_mode = 2
size_flags_vertical = 3

[node name="MarginContainer" type="MarginContainer" parent="CanvasLayer/Control/VBoxContainer"]
layout_mode = 2
theme_override_constants/margin_left = 60
theme_override_constants/margin_top = 30
theme_override_constants/margin_right = 60
theme_override_constants/margin_bottom = 120

[node name="StartARButton" type="Button" parent="CanvasLayer/Control/VBoxContainer/MarginContainer"]
custom_minimum_size = Vector2(0, 150)
layout_mode = 2
theme_override_font_sizes/font_size = 60
theme_override_styles/normal = SubResource("StyleBoxFlat_rr52s")
text = "Start AR"

[node name="XROrigin3D" type="XROrigin3D" parent="."]
current = true

[node name="MeshInstance3D" type="MeshInstance3D" parent="XROrigin3D"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -1)
mesh = SubResource("BoxMesh_wukjl")

[node name="Origin" type="MeshInstance3D" parent="XROrigin3D"]
mesh = SubResource("SphereMesh_yvi2r")

[node name="Label3D" type="Label3D" parent="XROrigin3D/Origin"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.190765, 0)
pixel_size = 0.0005
text = "Origin
↓"
font_size = 120
outline_size = 30

[node name="XRCamera3D" type="XRCamera3D" parent="XROrigin3D"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0.476125)
fov = 60.0

[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
environment = SubResource("Environment_603g6")

[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."]
transform = Transform3D(-0.866023, -0.433016, 0.250001, 0, 0.499998, 0.866027, -0.500003, 0.749999, -0.43301, 0, 0, 0)
shadow_enabled = true

[connection signal="pressed" from="CanvasLayer/Control/VBoxContainer/MarginContainer/StartARButton" to="." method="_on_start_ar_button_pressed"]
anchor_bottom = 0.5
offset_left = 40.0
offset_top = 250.0
offset_right = 320.0
offset_bottom = 312.0
text = "Hello GDExtension World"

[connection signal="pressed" from="Button" to="." method="_on_Button_pressed"]
75 changes: 75 additions & 0 deletions plugin/demo/main3D.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
extends Node3D

var _plugin_name = "ARCorePlugin"
var _android_plugin

var is_estimating_light = false
var original_light_trsf: Transform3D;

# Called when the node enters the scene tree for the first time.
func _ready():
for s in Engine.get_singleton_list():
print("MCT " + s.get_basename())
if Engine.has_singleton(_plugin_name):
print("MCT found plugin")
_android_plugin = Engine.get_singleton(_plugin_name)
else:
printerr("MCT Couldn't find plugin " + _plugin_name)

print("MCT before initialize_wrapper")
_android_plugin.initializeEnvironment()

print("MCT called initialize_wrapper")

var ar_interface = ARCoreInterfaceInstance.get_interface()
var interface_name = ar_interface.get_name()
print("MCT " + interface_name)

ARCoreInterfaceInstance.start()

original_light_trsf = $DirectionalLight3D.transform

func _exit_tree():
_android_plugin.uninitializeEnvironment()

# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
if (is_estimating_light):
var light_dir = ARCoreInterfaceInstance.get_light_main_hdr_direction()
$DirectionalLight3D.rotation = light_dir
var intensity = ARCoreInterfaceInstance.get_light_main_hdr_intensity()
$DirectionalLight3D.light_intensity_lumens = intensity.x;
else:
$DirectionalLight3D.transform = original_light_trsf


func _on_node_2d_estimate_depthmap_toggled(toggled):
ARCoreInterfaceInstance.enable_depth_estimation(toggled)

func _on_node_2d_show_depthmap_toggled(toggled):
ARCoreInterfaceInstance.show_depth_map(toggled)

func _on_node_2d_far_changed(value):
ARCoreInterfaceInstance.set_max_depth_meters(value)

func _on_node_2d_vertical_planes_toggled(toggled):
ARCoreInterfaceInstance.enable_vertical_plane_detection(toggled)

func _on_node_2d_horizontal_planes_toggled(toggled):
ARCoreInterfaceInstance.enable_horizontal_plane_detection(toggled)

func _on_node_2d_images_detection_toggled(toggled):
ARCoreInterfaceInstance.enable_images_detection(toggled)

func _on_node_2d_instant_placement_toggled(toggled):
ARCoreInterfaceInstance.enable_instant_placement(toggled)

func _on_node_2d_light_estimation_toggled(toggled):
is_estimating_light = toggled
ARCoreInterfaceInstance.enable_light_estimation(toggled)

func _on_node_2d_point_cloud_detection_toggled(toggled):
ARCoreInterfaceInstance.enable_point_cloud_detection(toggled)

func _on_node_2d_switch_orientation(vertical):
ARCoreInterfaceInstance.switch_orientation(vertical)
Loading

0 comments on commit 1509a01

Please sign in to comment.