diff --git a/addons/gdcef/demos/2D/CEF.gd b/addons/gdcef/demos/2D/CEF.gd index 1373177..91fe3bf 100644 --- a/addons/gdcef/demos/2D/CEF.gd +++ b/addons/gdcef/demos/2D/CEF.gd @@ -175,8 +175,8 @@ func _input(event): return if event is InputEventKey: current_browser.on_key_pressed( - event.unicode if event.unicode != 0 else event.scancode, - event.pressed, event.shift, event.alt, event.control) + event.unicode if event.unicode != 0 else event.keycode, # Godot3: event.scancode, + event.pressed, event.shift_pressed, event.alt_pressed, event.is_command_or_control_pressed()) pass # ============================================================================== diff --git a/addons/gdcef/demos/3D/CEF.tscn b/addons/gdcef/demos/3D/CEF.tscn index 13949b6..0ec6462 100644 --- a/addons/gdcef/demos/3D/CEF.tscn +++ b/addons/gdcef/demos/3D/CEF.tscn @@ -1,77 +1,85 @@ -[gd_scene load_steps=3 format=2] +[gd_scene load_steps=2 format=3 uid="uid://omfv5yo3uhfr"] -[ext_resource path="res://GUI.gd" type="Script" id=1] -[ext_resource path="res://libs/gdcef.gdns" type="Script" id=2] +[ext_resource type="Script" path="res://GUI.gd" id="1"] [node name="GUI" type="Control"] -margin_right = 280.0 -margin_bottom = 180.0 +layout_mode = 3 +anchors_preset = 0 +offset_right = 280.0 +offset_bottom = 180.0 mouse_filter = 1 -script = ExtResource( 1 ) +script = ExtResource("1") -[node name="CEF" type="Node" parent="."] -script = ExtResource( 2 ) +[node name="CEF" type="GDCef" parent="."] [node name="Panel" type="Panel" parent="."] +layout_mode = 0 anchor_right = 1.0 anchor_bottom = 1.0 [node name="TextureRect" type="TextureRect" parent="Panel"] +layout_mode = 0 anchor_top = 0.015 anchor_bottom = 0.015 -margin_left = 5.0 -margin_top = 28.3 -margin_right = 273.0 -margin_bottom = 158.3 +offset_left = 5.0 +offset_top = 28.3 +offset_right = 273.0 +offset_bottom = 158.3 mouse_filter = 0 -expand = true +expand_mode = 1 [node name="Label" type="Label" parent="Panel"] -margin_left = 4.0 -margin_top = 163.0 -margin_right = 81.0 -margin_bottom = 177.0 +layout_mode = 0 +offset_left = 4.0 +offset_top = 163.0 +offset_right = 81.0 +offset_bottom = 177.0 mouse_filter = 0 text = "Hello world!" [node name="Label2" type="Label" parent="Panel"] -margin_left = 7.0 -margin_top = 7.0 -margin_right = 41.0 -margin_bottom = 21.0 +layout_mode = 0 +offset_left = 7.0 +offset_top = 7.0 +offset_right = 41.0 +offset_bottom = 21.0 mouse_filter = 0 text = "URL:" [node name="Home" type="Button" parent="Panel"] -margin_left = 208.0 -margin_top = 3.0 -margin_right = 259.0 -margin_bottom = 25.0 +layout_mode = 0 +offset_left = 208.0 +offset_top = 3.0 +offset_right = 259.0 +offset_bottom = 25.0 text = "Home" [node name="Prev" type="Button" parent="Panel"] -margin_left = 186.0 -margin_top = 3.0 -margin_right = 206.0 -margin_bottom = 25.0 +layout_mode = 0 +offset_left = 186.0 +offset_top = 3.0 +offset_right = 206.0 +offset_bottom = 25.0 text = "<" [node name="Next" type="Button" parent="Panel"] -margin_left = 259.0 -margin_top = 3.0 -margin_right = 279.0 -margin_bottom = 25.0 +layout_mode = 0 +offset_left = 259.0 +offset_top = 3.0 +offset_right = 279.0 +offset_bottom = 25.0 text = ">" [node name="TextEdit" type="LineEdit" parent="Panel"] -margin_left = 43.0 -margin_top = 2.0 -margin_right = 185.0 -margin_bottom = 26.0 +layout_mode = 0 +offset_left = 43.0 +offset_top = 2.0 +offset_right = 185.0 +offset_bottom = 26.0 [connection signal="gui_input" from="Panel/TextureRect" to="." method="_on_TextureRect_gui_input"] [connection signal="pressed" from="Panel/Home" to="." method="_on_Home_pressed"] [connection signal="pressed" from="Panel/Prev" to="." method="_on_Prev_pressed"] -[connection signal="pressed" from="Panel/Next" to="." method="_on_Prev_pressed"] [connection signal="pressed" from="Panel/Next" to="." method="_on_Next_pressed"] +[connection signal="pressed" from="Panel/Next" to="." method="_on_Prev_pressed"] [connection signal="text_changed" from="Panel/TextEdit" to="." method="_on_TextEdit_text_changed"] diff --git a/addons/gdcef/demos/3D/GUI.gd b/addons/gdcef/demos/3D/GUI.gd index c392e9a..9337842 100644 --- a/addons/gdcef/demos/3D/GUI.gd +++ b/addons/gdcef/demos/3D/GUI.gd @@ -7,18 +7,18 @@ extends Control # Name of the browser -const browser1 = "browser1" +const browser_name = "browser1" # Memorize if the mouse was pressed -var mouse_pressed : bool = false +@onready var mouse_pressed : bool = false # ============================================================================== # Home button pressed: get the browser node and load a new page. # ============================================================================== func _on_Home_pressed(): - var browser = $CEF.get_node(browser1) + var browser = $CEF.get_node(browser_name) if browser == null: - $Panel/Label.set_text("Failed getting Godot node " + browser1) + $Panel/Label.set_text("Failed getting Godot node " + browser_name) return browser.load_url("https://bitbucket.org/chromiumembedded/cef/wiki/Home") pass @@ -27,9 +27,9 @@ func _on_Home_pressed(): # Go to previously visited page # ============================================================================== func _on_Prev_pressed(): - var browser = $CEF.get_node(browser1) + var browser = $CEF.get_node(browser_name) if browser == null: - $Panel/Label.set_text("Failed getting Godot node " + browser1) + $Panel/Label.set_text("Failed getting Godot node " + browser_name) return browser.previous_page() pass @@ -38,9 +38,9 @@ func _on_Prev_pressed(): # Go to next page # ============================================================================== func _on_Next_pressed(): - var browser = $CEF.get_node(browser1) + var browser = $CEF.get_node(browser_name) if browser == null: - $Panel/Label.set_text("Failed getting Godot node " + browser1) + $Panel/Label.set_text("Failed getting Godot node " + browser_name) return browser.next_page() pass @@ -55,9 +55,9 @@ func _on_page_loaded(node): # On new URL entered # ============================================================================== func _on_TextEdit_text_changed(new_text): - var browser = $CEF.get_node(browser1) + var browser = $CEF.get_node(browser_name) if browser == null: - $Panel/Label.set_text("Failed getting Godot node " + browser1) + $Panel/Label.set_text("Failed getting Godot node " + browser_name) return browser.load_url(new_text) @@ -65,30 +65,30 @@ func _on_TextEdit_text_changed(new_text): # Get mouse events and broadcast them to CEF # ============================================================================== func _on_TextureRect_gui_input(event): - var browser = $CEF.get_node(browser1) + var browser = $CEF.get_node(browser_name) if browser == null: - $Panel/Label.set_text("Failed getting Godot node " + browser1) + $Panel/Label.set_text("Failed getting Godot node " + browser_name) return if event is InputEventMouseButton: - if event.button_index == BUTTON_WHEEL_UP: + if event.button_index == MOUSE_BUTTON_WHEEL_UP: browser.on_mouse_wheel_vertical(2) - elif event.button_index == BUTTON_WHEEL_DOWN: + elif event.button_index == MOUSE_BUTTON_WHEEL_DOWN: browser.on_mouse_wheel_vertical(-2) - elif event.button_index == BUTTON_LEFT: + elif event.button_index == MOUSE_BUTTON_LEFT: mouse_pressed = event.pressed - if event.pressed == true: + if mouse_pressed: browser.on_mouse_left_down() else: browser.on_mouse_left_up() - elif event.button_index == BUTTON_RIGHT: + elif event.button_index == MOUSE_BUTTON_RIGHT: mouse_pressed = event.pressed - if event.pressed == true: + if mouse_pressed: browser.on_mouse_right_down() else: browser.on_mouse_right_up() else: mouse_pressed = event.pressed - if event.pressed == true: + if mouse_pressed: browser.on_mouse_middle_down() else: browser.on_mouse_middle_up() @@ -102,23 +102,20 @@ func _on_TextureRect_gui_input(event): # Make the CEF browser reacts from keyboard events. # ============================================================================== func _input(event): - var browser = $CEF.get_node(browser1) + var browser = $CEF.get_node(browser_name) if browser == null: - $Panel/Label.set_text("Failed getting Godot node " + browser1) + $Panel/Label.set_text("Failed getting Godot node " + browser_name) return if event is InputEventKey: - if event.unicode != 0: - browser.on_key_pressed(event.unicode, event.pressed, event.shift, event.alt, event.control) - else: - browser.on_key_pressed(event.scancode, event.pressed, event.shift, event.alt, event.control) - + browser.on_key_pressed( + event.unicode if event.unicode != 0 else event.keycode, # Godot3: event.scancode, + event.pressed, event.shift_pressed, event.alt_pressed, event.is_command_or_control_pressed()) pass # ============================================================================== -# Create a single briwser named "browser1" that is attached as child node to $CEF. +# Create a single briwser named "browser_name" that is attached as child node to $CEF. # ============================================================================== func _ready(): - # Configuration are: # resource_path := {"artifacts", CEF_ARTIFACTS_FOLDER} # resource_path := {"exported_artifacts", application_real_path()} @@ -143,9 +140,11 @@ func _ready(): get_tree().quit() return + # wait one frame for the texture rect to get its size + await get_tree().process_frame var S = $Panel/TextureRect.get_size() - var browser = $CEF.create_browser("https://github.com/Lecrapouille/gdcef", browser1, S.x, S.y, {"javascript":true}) - browser.connect("page_loaded", self, "_on_page_loaded") + var browser = $CEF.create_browser("https://github.com/Lecrapouille/gdcef", browser_name, S.x, S.y, {"javascript":true}) + browser.connect("page_loaded", Callable(self, "_on_page_loaded")) $Panel/TextureRect.texture = browser.get_texture() # ============================================================================== diff --git a/addons/gdcef/demos/3D/default_env.tres b/addons/gdcef/demos/3D/default_env.tres index b805105..f932820 100644 --- a/addons/gdcef/demos/3D/default_env.tres +++ b/addons/gdcef/demos/3D/default_env.tres @@ -1,6 +1,6 @@ [gd_resource type="Environment" load_steps=2 format=2] -[sub_resource type="ProceduralSky" id=1] +[sub_resource type="Sky" id=1] [resource] background_mode = 2 diff --git a/addons/gdcef/demos/3D/gui_3d.gd b/addons/gdcef/demos/3D/gui_3d.gd index 33a6d3d..fda8ab6 100644 --- a/addons/gdcef/demos/3D/gui_3d.gd +++ b/addons/gdcef/demos/3D/gui_3d.gd @@ -1,33 +1,27 @@ -extends Spatial +extends Node3D # The size of the quad mesh itself. var quad_mesh_size -# Used for checking if the mouse is inside the Area +# Used for checking if the mouse is inside the Area3D var is_mouse_inside = false -# Used for checking if the mouse was pressed inside the Area +# Used for checking if the mouse was pressed inside the Area3D var is_mouse_held = false # The last non-empty mouse position. Used when dragging outside of the box. var last_mouse_pos3D = null # The last processed input touch/mouse event. To calculate relative movement. var last_mouse_pos2D = null -onready var node_viewport = $Viewport -onready var node_quad = $Quad -onready var node_area = $Quad/Area +@onready var node_viewport = $SubViewport +@onready var node_quad = $Quad +@onready var node_area = $Quad/Area3D func _ready(): - node_area.connect("mouse_entered", self, "_mouse_entered_area") + node_area.mouse_entered.connect(self._mouse_entered_area) # If the material is NOT set to use billboard settings, then avoid running billboard specific code - if node_quad.get_surface_material(0).params_billboard_mode == 0: + if node_quad.get_surface_override_material(0).billboard_mode == BaseMaterial3D.BillboardMode.BILLBOARD_DISABLED: set_process(false) - if OS.get_current_video_driver() == OS.VIDEO_DRIVER_GLES2: - # Required to prevent the texture from being too dark when using GLES2. - # This should be left to `true` in GLES3 to prevent the texture from looking - # washed out there. - node_quad.get_surface_material(0).flags_albedo_tex_force_srgb = false - func _process(_delta): # NOTE: Remove this function if you don't plan on using billboard settings. @@ -42,7 +36,7 @@ func _unhandled_input(event): # Check if the event is a non-mouse/non-touch event var is_mouse_event = false for mouse_event in [InputEventMouseButton, InputEventMouseMotion, InputEventScreenDrag, InputEventScreenTouch]: - if event is mouse_event: + if is_instance_of(event, mouse_event): is_mouse_event = true break @@ -52,10 +46,10 @@ func _unhandled_input(event): if is_mouse_event and (is_mouse_inside or is_mouse_held): handle_mouse(event) elif not is_mouse_event: - node_viewport.input(event) + node_viewport.push_input(event) -# Handle mouse events inside Area. (Area.input_event had many issues with dragging) +# Handle mouse events inside Area3D. (Area3D.input_event had many issues with dragging) func handle_mouse(event): # Get mesh size to detect edges and make conversions. This code only support PlaneMesh and QuadMesh. quad_mesh_size = node_quad.mesh.size @@ -64,15 +58,15 @@ func handle_mouse(event): if event is InputEventMouseButton or event is InputEventScreenTouch: is_mouse_held = event.pressed - # Find mouse position in Area + # Find mouse position in Area3D var mouse_pos3D = find_mouse(event.global_position) # Check if the mouse is outside of bounds, use last position to avoid errors # NOTE: mouse_exited signal was unrealiable in this situation is_mouse_inside = mouse_pos3D != null if is_mouse_inside: - # Convert click_pos from world coordinate space to a coordinate space relative to the Area node. - # NOTE: affine_inverse accounts for the Area node's scale, rotation, and translation in the scene! + # Convert click_pos from world coordinate space to a coordinate space relative to the Area3D node. + # NOTE: affine_inverse accounts for the Area3D node's scale, rotation, and position in the scene! mouse_pos3D = node_area.global_transform.affine_inverse() * mouse_pos3D last_mouse_pos3D = mouse_pos3D else: @@ -115,20 +109,23 @@ func handle_mouse(event): last_mouse_pos2D = mouse_pos2D # Finally, send the processed input event to the viewport. - node_viewport.input(event) + node_viewport.push_input(event) func find_mouse(global_position): - var camera = get_viewport().get_camera() - - # From camera center to the mouse position in the Area - var from = camera.project_ray_origin(global_position) + var camera = get_viewport().get_camera_3d() var dist = find_further_distance_to(camera.transform.origin) - var to = from + camera.project_ray_normal(global_position) * dist + # From camera center to the mouse position in the Area3D. + var parameters = PhysicsRayQueryParameters3D.new() + parameters.from = camera.project_ray_origin(global_position) + parameters.to = parameters.from + camera.project_ray_normal(global_position) * dist - # Manually raycasts the are to find the mouse position - var result = get_world().direct_space_state.intersect_ray(from, to, [], node_area.collision_layer,false,true) #for 3.1 changes + # Manually raycasts the area to find the mouse position. + parameters.collision_mask = node_area.collision_layer + parameters.collide_with_bodies = false + parameters.collide_with_areas = true + var result = get_world_3d().direct_space_state.intersect_ray(parameters) if result.size() > 0: return result.position @@ -156,15 +153,15 @@ func find_further_distance_to(origin): func rotate_area_to_billboard(): - var billboard_mode = node_quad.get_surface_material(0).params_billboard_mode + var billboard_mode = node_quad.get_surface_override_material(0).params_billboard_mode # Try to match the area with the material's billboard setting, if enabled if billboard_mode > 0: # Get the camera - var camera = get_viewport().get_camera() + var camera = get_viewport().get_camera_3d() # Look in the same direction as the camera var look = camera.to_global(Vector3(0, 0, -100)) - camera.global_transform.origin - look = node_area.translation + look + look = node_area.position + look # Y-Billboard: Lock Y rotation, but gives bad results if the camera is tilted. if billboard_mode == 2: diff --git a/addons/gdcef/demos/3D/gui_in_3d.tscn b/addons/gdcef/demos/3D/gui_in_3d.tscn index 9d509ba..277c39d 100644 --- a/addons/gdcef/demos/3D/gui_in_3d.tscn +++ b/addons/gdcef/demos/3D/gui_in_3d.tscn @@ -1,78 +1,101 @@ -[gd_scene load_steps=6 format=2] +[gd_scene load_steps=10 format=3 uid="uid://0iek6ri88gkb"] -[ext_resource path="res://gui_panel_3d.tscn" type="PackedScene" id=1] +[ext_resource type="PackedScene" uid="uid://dvl383ispakmn" path="res://gui_panel_3d.tscn" id="1"] -[sub_resource type="Animation" id=1] +[sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_1lgdv"] +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_pq42j"] +sky_material = SubResource("ProceduralSkyMaterial_1lgdv") + +[sub_resource type="Environment" id="Environment_niyks"] +background_mode = 2 +sky = SubResource("Sky_pq42j") +tonemap_mode = 2 +glow_enabled = true + +[sub_resource type="Animation" id="1"] length = 6.0 -loop = true +loop_mode = 1 tracks/0/type = "value" -tracks/0/path = NodePath("Camera:transform") -tracks/0/interp = 1 -tracks/0/loop_wrap = true tracks/0/imported = false tracks/0/enabled = true +tracks/0/path = NodePath("Camera3D:transform") +tracks/0/interp = 1 +tracks/0/loop_wrap = true tracks/0/keys = { -"times": PoolRealArray( 0, 2, 4, 6 ), -"transitions": PoolRealArray( 1, 1, 1, 1 ), +"times": PackedFloat32Array(0, 2, 4, 6), +"transitions": PackedFloat32Array(-2, -2, -2, -2), "update": 0, -"values": [ Transform( 0.994592, 0, 0.103856, 0, 1, 0, -0.103856, 0, 0.994592, 0.465682, 0, 1.78523 ), Transform( 0.962984, 0, -0.269557, 0, 1, 0, 0.269557, 0, 0.962984, -0.462237, 0, 2.41934 ), Transform( 0.806599, 0, -0.591098, 0, 1, 0, 0.591098, 0, 0.806599, -1.59502, 0, 2.05358 ), Transform( 0.994592, 0, 0.103856, 0, 1, 0, -0.103856, 0, 0.994592, 0.465682, 0, 1.78523 ) ] +"values": [Transform3D(0.994592, 0, 0.103856, 0, 1, 0, -0.103856, 0, 0.994592, 0.465682, 0, 1.78523), Transform3D(0.962984, 0, -0.269557, 0, 1, 0, 0.269557, 0, 0.962984, -0.462237, 0, 2.41934), Transform3D(0.806599, 0, -0.591098, 0, 1, 0, 0.591098, 0, 0.806599, -1.59502, 0, 2.05358), Transform3D(0.994592, 0, 0.103856, 0, 1, 0, -0.103856, 0, 0.994592, 0.465682, 0, 1.78523)] +} + +[sub_resource type="AnimationLibrary" id="AnimationLibrary_uw4n0"] +_data = { +"Move_camera": SubResource("1") } -[sub_resource type="PlaneMesh" id=2] +[sub_resource type="PlaneMesh" id="2"] -[sub_resource type="CubeMesh" id=3] +[sub_resource type="BoxMesh" id="3"] -[sub_resource type="SpatialMaterial" id=4] -albedo_color = Color( 0.722656, 0.791992, 1, 1 ) +[sub_resource type="StandardMaterial3D" id="4"] +albedo_color = Color(0.722656, 0.791992, 1, 1) roughness = 0.0 -[node name="GUIin3D" type="Spatial"] +[node name="GUIin3D" type="Node3D"] -[node name="GUIPanel3D" parent="." instance=ExtResource( 1 )] +[node name="WorldEnvironment" type="WorldEnvironment" parent="."] +environment = SubResource("Environment_niyks") -[node name="Camera" type="Camera" parent="."] -transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 0.999999, 0, 0, 3 ) +[node name="GUIPanel3D" parent="." instance=ExtResource("1")] + +[node name="Camera3D" type="Camera3D" parent="."] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 0.999999, 0, 0, 3) fov = 74.0 near = 0.1 -[node name="OmniLight" type="OmniLight" parent="."] -transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 1.38866, 1.2413, 2.72141 ) +[node name="OmniLight3D" type="OmniLight3D" parent="."] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 1.38866, 1.2413, 2.72141) shadow_enabled = true +shadow_blur = 3.0 omni_range = 10.0 [node name="Camera_Move" type="AnimationPlayer" parent="."] +libraries = { +"": SubResource("AnimationLibrary_uw4n0") +} autoplay = "Move_camera" -playback_speed = 0.25 -anims/Move_camera = SubResource( 1 ) -[node name="Background" type="Spatial" parent="."] +[node name="Background" type="Node3D" parent="."] -[node name="Wall" type="MeshInstance" parent="Background"] -transform = Transform( 4, 0, 0, 0, -1.74846e-07, -4, 0, 4, -1.74846e-07, -2.60819, 0.589247, -2.08943 ) -mesh = SubResource( 2 ) +[node name="Wall" type="MeshInstance3D" parent="Background"] +transform = Transform3D(4, 0, 0, 0, -1.74846e-07, -4, 0, 4, -1.74846e-07, -2.60819, 0.589247, -2.08943) +mesh = SubResource("2") -[node name="Wall2" type="MeshInstance" parent="Background"] -transform = Transform( 4, 0, 0, 0, -1.74846e-07, -4, 0, 4, -1.74846e-07, 5.08055, 0.589247, -2.08943 ) -mesh = SubResource( 2 ) +[node name="Wall2" type="MeshInstance3D" parent="Background"] +transform = Transform3D(4, 0, 0, 0, -1.74846e-07, -4, 0, 4, -1.74846e-07, 5.08055, 0.589247, -2.08943) +mesh = SubResource("2") -[node name="Wall3" type="MeshInstance" parent="Background"] -transform = Transform( -1.74846e-07, -4, 0, -1.74846e-07, 7.64274e-15, -4, 4, -1.74846e-07, -1.74846e-07, 9.04446, 0.589247, 1.62058 ) -mesh = SubResource( 2 ) +[node name="Wall3" type="MeshInstance3D" parent="Background"] +transform = Transform3D(-1.74846e-07, -4, 0, -1.74846e-07, 7.64274e-15, -4, 4, -1.74846e-07, -1.74846e-07, 9.04446, 0.589247, 1.62058) +mesh = SubResource("2") -[node name="Floor" type="MeshInstance" parent="Background"] -transform = Transform( 4, 0, 0, 0, 4, 0, 0, 0, 4, -2.60819, -2.68765, 1.46502 ) -mesh = SubResource( 2 ) +[node name="Floor" type="MeshInstance3D" parent="Background"] +transform = Transform3D(4, 0, 0, 0, 4, 0, 0, 0, 4, -2.60819, -2.68765, 1.46502) +mesh = SubResource("2") -[node name="Floor2" type="MeshInstance" parent="Background"] -transform = Transform( 4, 0, 0, 0, 4, 0, 0, 0, 4, 5.08055, -2.68765, 1.46502 ) -mesh = SubResource( 2 ) +[node name="Floor2" type="MeshInstance3D" parent="Background"] +transform = Transform3D(4, 0, 0, 0, 4, 0, 0, 0, 4, 5.08055, -2.68765, 1.46502) +mesh = SubResource("2") -[node name="Cube" type="MeshInstance" parent="Background"] -transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 4.25901, -0.598608, 0.374871 ) -mesh = SubResource( 3 ) -material/0 = SubResource( 4 ) +[node name="Cube" type="MeshInstance3D" parent="Background"] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 4.25901, -0.598608, 0.374871) +mesh = SubResource("3") +surface_material_override/0 = SubResource("4") -[node name="Cube2" type="MeshInstance" parent="Background"] -transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 2.88761, 2.01326, 0.374871 ) -mesh = SubResource( 3 ) -material/0 = SubResource( 4 ) +[node name="Cube2" type="MeshInstance3D" parent="Background"] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 2.88761, 2.01326, 0.374871) +mesh = SubResource("3") +surface_material_override/0 = SubResource("4") diff --git a/addons/gdcef/demos/3D/gui_panel_3d.tscn b/addons/gdcef/demos/3D/gui_panel_3d.tscn index b674786..b1782cd 100644 --- a/addons/gdcef/demos/3D/gui_panel_3d.tscn +++ b/addons/gdcef/demos/3D/gui_panel_3d.tscn @@ -1,43 +1,41 @@ -[gd_scene load_steps=7 format=2] +[gd_scene load_steps=7 format=3 uid="uid://dvl383ispakmn"] -[ext_resource path="res://gui_3d.gd" type="Script" id=1] -[ext_resource path="res://CEF.tscn" type="PackedScene" id=2] +[ext_resource type="Script" path="res://gui_3d.gd" id="1"] +[ext_resource type="PackedScene" uid="uid://omfv5yo3uhfr" path="res://CEF.tscn" id="2_06vtd"] -[sub_resource type="QuadMesh" id=1] -size = Vector2( 3, 2 ) +[sub_resource type="QuadMesh" id="1"] +size = Vector2(3, 2) -[sub_resource type="ViewportTexture" id=2] -viewport_path = NodePath("Viewport") +[sub_resource type="ViewportTexture" id="2"] +viewport_path = NodePath("SubViewport") -[sub_resource type="SpatialMaterial" id=3] +[sub_resource type="StandardMaterial3D" id="3"] resource_local_to_scene = true -flags_transparent = true -flags_unshaded = true -flags_albedo_tex_force_srgb = true -albedo_texture = SubResource( 2 ) +transparency = 1 +shading_mode = 0 +albedo_texture = SubResource("2") -[sub_resource type="BoxShape" id=4] -extents = Vector3( 1.5, 1, 0.05 ) +[sub_resource type="BoxShape3D" id="4"] +size = Vector3(3, 2, 0.1) -[node name="GUIPanel3D" type="Spatial"] -script = ExtResource( 1 ) +[node name="GUIPanel3D" type="Node3D"] +process_mode = 3 +script = ExtResource("1") -[node name="Viewport" type="Viewport" parent="."] -size = Vector2( 280, 180 ) -hdr = false -usage = 0 -render_target_v_flip = true -render_target_update_mode = 3 +[node name="SubViewport" type="SubViewport" parent="."] +gui_embed_subwindows = true +size = Vector2i(280, 180) +render_target_update_mode = 4 -[node name="GUI" parent="Viewport" instance=ExtResource( 2 )] +[node name="GUI" parent="SubViewport" instance=ExtResource("2_06vtd")] -[node name="Quad" type="MeshInstance" parent="."] -mesh = SubResource( 1 ) -material/0 = SubResource( 3 ) +[node name="Quad" type="MeshInstance3D" parent="."] +mesh = SubResource("1") +surface_material_override/0 = SubResource("3") -[node name="Area" type="Area" parent="Quad"] +[node name="Area3D" type="Area3D" parent="Quad"] collision_layer = 2 input_capture_on_drag = true -[node name="CollisionShape" type="CollisionShape" parent="Quad/Area"] -shape = SubResource( 4 ) +[node name="CollisionShape3D" type="CollisionShape3D" parent="Quad/Area3D"] +shape = SubResource("4") diff --git a/addons/gdcef/demos/3D/project.godot b/addons/gdcef/demos/3D/project.godot index 38ba98f..4347b82 100644 --- a/addons/gdcef/demos/3D/project.godot +++ b/addons/gdcef/demos/3D/project.godot @@ -6,29 +6,20 @@ ; [section] ; section goes between [] ; param=value ; assign values to parameters -config_version=4 - -_global_script_classes=[ { -"base": "", -"class": "GDCef", -"language": "NativeScript", -"path": "res://libs/gdcef.gdns" -} ] -_global_script_class_icons={ -"GDCef": "" -} +config_version=5 [application] -config/name="CEF in 3D" -config/description="A demo showing a CEF instanced within a 3D scene using viewports, +config/name="GUI in 3D" +config/description="A demo showing a GUI instanced within a 3D scene using viewports, as well as forwarding mouse and keyboard input to the GUI." run/main_scene="res://gui_in_3d.tscn" +config/features=PackedStringArray("4.2") config/icon="res://icon.png" [gdnative] -singletons=[ ] +singletons=[] [layer_names] @@ -36,11 +27,7 @@ singletons=[ ] [rendering] -quality/driver/fallback_to_gles2=true -quality/intended_usage/framebuffer_allocation=3 -vram_compression/import_etc=true -quality/shadow_atlas/size=2048 -quality/shadow_atlas/size.mobile=1024 -quality/shadows/filter_mode=2 -quality/filters/msaa=2 +renderer/rendering_method="gl_compatibility" +anti_aliasing/quality/msaa_3d=2 +anti_aliasing/quality/use_debanding=true environment/default_environment="res://default_env.tres" diff --git a/addons/gdcef/demos/HelloCEF/Control.gd b/addons/gdcef/demos/HelloCEF/Control.gd index 4d5764e..ea0a5a6 100644 --- a/addons/gdcef/demos/HelloCEF/Control.gd +++ b/addons/gdcef/demos/HelloCEF/Control.gd @@ -8,7 +8,7 @@ extends Control # ============================================================================== # Hold URLs we want to load. -var pages = [ +const pages = [ "https://github.com/Lecrapouille/gdcef", "https://bitbucket.org/chromiumembedded/cef/wiki/Home", "https://docs.godotengine.org/", @@ -17,14 +17,14 @@ var pages = [ "https://www.localeplanet.com/support/browser.html" ] # Iterator on the array holding URLs. -var iterator = 0 +@onready var iterator = 0 # The left browser is allowed for mouse and keyboard interaction. # The right browser is disable because we are automatically switching of pages. -var active_browser = "left" +@onready var active_browser = "left" # Memorize if the mouse was pressed -var mouse_pressed : bool = false +@onready var mouse_pressed : bool = false # ============================================================================== # Timer callback: every 6 seconds load a new webpage. @@ -54,19 +54,19 @@ func _on_Texture1_gui_input(event): browser.on_mouse_wheel_vertical(-2) elif event.button_index == MOUSE_BUTTON_LEFT: mouse_pressed = event.pressed - if event.button_pressed == true: + if mouse_pressed: browser.on_mouse_left_down() else: browser.on_mouse_left_up() elif event.button_index == MOUSE_BUTTON_RIGHT: mouse_pressed = event.pressed - if event.button_pressed == true: + if mouse_pressed: browser.on_mouse_right_down() else: browser.on_mouse_right_up() else: mouse_pressed = event.pressed - if event.button_pressed == true: + if mouse_pressed: browser.on_mouse_middle_down() else: browser.on_mouse_middle_up() @@ -85,11 +85,9 @@ func _input(event): $Panel/Label.set_text("Failed getting Godot node 'left'") return if event is InputEventKey: - if event.unicode != 0: - browser.on_key_pressed(event.unicode, event.pressed, event.shift, event.alt, event.control) - else: - browser.on_key_pressed(event.keycode, event.pressed, event.shift, event.alt, event.control) - + browser.on_key_pressed( + event.unicode if event.unicode != 0 else event.keycode, # Godot3: event.scancode, + event.pressed, event.shift_pressed, event.alt_pressed, event.is_command_or_control_pressed()) pass # ============================================================================== @@ -133,6 +131,8 @@ func _ready(): ### Browsers ############################################################### + # wait one frame for the texture rect to get its size + await get_tree().process_frame # Left browser is displaying the first webpage with a 3D scene, we are # enabling webgl. Other default configuration are: # {"frame_rate", 30}