Browse Source

Merge pull request #299 from TwistedTwigleg/gui_in_3d_fix

Rewrote most of the code in the gui_in_3d demo.
Aaron Franke 5 years ago
parent
commit
de309f0544

+ 0 - 193
viewport/gui_in_3d/Gui_in_3D.tscn

@@ -1,193 +0,0 @@
-[gd_scene load_steps=15 format=2]
-
-[ext_resource path="res://gui_3d.gd" type="Script" id=1]
-
-[sub_resource type="PlaneMesh" id=1]
-
-[sub_resource type="ViewportTexture" id=2]
-flags = 5
-viewport_path = NodePath("Viewport")
-
-[sub_resource type="SpatialMaterial" id=3]
-resource_local_to_scene = true
-flags_unshaded = true
-flags_albedo_tex_force_srgb = true
-params_diffuse_mode = 1
-albedo_texture = SubResource( 2 )
-
-[sub_resource type="GDScript" id=4]
-script/source = "tool
-extends Object
-func e():
-	return 0.01
-"
-
-[sub_resource type="BoxShape" id=5]
-extents = Vector3( 1, 1, 0.01 )
-script = SubResource( 4 )
-
-[sub_resource type="Animation" id=6]
-length = 6.0
-loop = true
-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/keys = {
-"times": PoolRealArray( 0, 2, 4, 6 ),
-"transitions": PoolRealArray( 1, 1, 1, 1 ),
-"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 ) ]
-}
-
-[sub_resource type="PlaneMesh" id=7]
-
-[sub_resource type="GDScript" id=8]
-script/source = "tool
-extends Object
-func e():
-	return 0
-"
-
-[sub_resource type="GDScript" id=9]
-script/source = "tool
-extends Object
-func e():
-	return 90
-"
-
-[sub_resource type="GDScript" id=10]
-script/source = "tool
-extends Object
-func e():
-	return 0
-"
-
-[sub_resource type="CubeMesh" id=11]
-
-[sub_resource type="SpatialMaterial" id=12]
-albedo_color = Color( 0.722656, 0.791992, 1, 1 )
-roughness = 0.0
-
-[sub_resource type="GDScript" id=13]
-script/source = "tool
-extends Object
-func e():
-	return 0
-"
-
-[node name="Gui_in_3D" type="Spatial"]
-script = ExtResource( 1 )
-
-[node name="Viewport" type="Viewport" parent="."]
-editor/display_folded = true
-size = Vector2( 180, 180 )
-transparent_bg = true
-hdr = false
-usage = 0
-render_target_v_flip = true
-
-[node name="GUI" type="Control" parent="Viewport"]
-margin_right = 40.0
-margin_bottom = 40.0
-mouse_filter = 1
-
-[node name="Label" type="Label" parent="Viewport/GUI"]
-margin_left = 44.0
-margin_top = 27.0
-margin_right = 121.0
-margin_bottom = 41.0
-text = "Hello world!"
-
-[node name="Button" type="Button" parent="Viewport/GUI"]
-margin_left = 18.0
-margin_top = 46.0
-margin_right = 155.0
-margin_bottom = 73.0
-text = "A button!"
-
-[node name="HSlider" type="HSlider" parent="Viewport/GUI"]
-margin_left = 14.0
-margin_top = 118.0
-margin_right = 157.0
-margin_bottom = 134.0
-
-[node name="TextEdit" type="LineEdit" parent="Viewport/GUI"]
-margin_left = 18.0
-margin_top = 87.0
-margin_right = 156.0
-margin_bottom = 111.0
-
-[node name="Area" type="Area" parent="."]
-input_ray_pickable = true
-input_capture_on_drag = true
-
-[node name="Quad" type="MeshInstance" parent="Area"]
-transform = Transform( 1, 0, 0, 0, -4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 0, 0 )
-mesh = SubResource( 1 )
-material/0 = SubResource( 3 )
-
-[node name="CollisionShape" type="CollisionShape" parent="Area"]
-shape = SubResource( 5 )
-
-[node name="Camera" type="Camera" parent="."]
-transform = Transform( 0.994592, 0, 0.103856, 0, 1, 0, -0.103856, 0, 0.994592, 0.465682, 0, 1.78523 )
-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 )
-shadow_enabled = true
-omni_range = 10.0
-
-[node name="Camera_Move" type="AnimationPlayer" parent="."]
-autoplay = "Move_camera"
-anims/Move_camera = SubResource( 6 )
-
-[node name="3D_background" type="Spatial" parent="."]
-editor/display_folded = true
-
-[node name="Wall" type="MeshInstance" parent="3D_background"]
-transform = Transform( 4, 0, 0, 0, -1.74846e-07, -4, 0, 4, -1.74846e-07, -2.60819, 0.589247, -2.08943 )
-mesh = SubResource( 7 )
-material/0 = null
-script = SubResource( 8 )
-
-[node name="Wall2" type="MeshInstance" parent="3D_background"]
-transform = Transform( 4, 0, 0, 0, -1.74846e-07, -4, 0, 4, -1.74846e-07, 5.08055, 0.589247, -2.08943 )
-mesh = SubResource( 7 )
-material/0 = null
-script = SubResource( 8 )
-
-[node name="Wall3" type="MeshInstance" parent="3D_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( 7 )
-material/0 = null
-script = SubResource( 9 )
-
-[node name="Floor" type="MeshInstance" parent="3D_background"]
-transform = Transform( 4, 0, 0, 0, 4, 0, 0, 0, 4, -2.60819, -2.68765, 1.46502 )
-mesh = SubResource( 7 )
-material/0 = null
-script = SubResource( 10 )
-
-[node name="Floor2" type="MeshInstance" parent="3D_background"]
-transform = Transform( 4, 0, 0, 0, 4, 0, 0, 0, 4, 5.08055, -2.68765, 1.46502 )
-mesh = SubResource( 7 )
-material/0 = null
-script = SubResource( 10 )
-
-[node name="Cube" type="MeshInstance" parent="3D_background"]
-transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 4.25901, -0.598608, 0.374871 )
-mesh = SubResource( 11 )
-material/0 = SubResource( 12 )
-script = SubResource( 13 )
-
-[node name="Cube2" type="MeshInstance" parent="3D_background"]
-transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 2.88761, 2.01326, 0.374871 )
-mesh = SubResource( 11 )
-material/0 = SubResource( 12 )
-script = SubResource( 13 )
-

+ 0 - 1
viewport/gui_in_3d/default_env.tres

@@ -23,4 +23,3 @@ ambient_light_energy = 0.28
 ambient_light_sky_contribution = 0.0
 ambient_light_sky_contribution = 0.0
 ssao_blur = 1
 ssao_blur = 1
 script = SubResource( 2 )
 script = SubResource( 2 )
-

+ 158 - 56
viewport/gui_in_3d/gui_3d.gd

@@ -1,70 +1,172 @@
 extends Spatial
 extends Spatial
-
 # Member variables
 # Member variables
-var prev_pos = null
-var last_click_pos = null
-var viewport = null
+# The size of the quad mesh itself.
+var quad_mesh_size
+# Used for checking if the mouse is inside the Area
+var is_mouse_inside = false
+# Used for checking if the mouse was pressed inside the Area
+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
+# Most used nodes
+onready var node_viewport = $Viewport
+onready var node_quad = $Quad
+onready var node_area = $Quad/Area
+
+
+func _ready():
+	node_area.connect("mouse_entered", 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:
+		set_process(false)
+
+
+func _process(_delta):
+	# NOTE: Remove this function if you don't plan on using billboard settings.
+	rotate_area_to_billboard()
+
+
+func _mouse_entered_area():
+	is_mouse_inside = true
 
 
 
 
 func _input(event):
 func _input(event):
-	# Check if the event is a non-mouse event
+	# Check if the event is a non-mouse/non-touch event
 	var is_mouse_event = false
 	var is_mouse_event = false
-	var mouse_events = [InputEventMouseButton, InputEventMouseMotion, InputEventScreenDrag, InputEventScreenTouch]
-	for mouse_event in mouse_events:
+	for mouse_event in [InputEventMouseButton, InputEventMouseMotion, InputEventScreenDrag, InputEventScreenTouch]:
 		if event is mouse_event:
 		if event is mouse_event:
 			is_mouse_event = true
 			is_mouse_event = true
 			break
 			break
-  
-	# If it is, then pass the event to the viewport
-	if is_mouse_event == false:
-		viewport.input(event)
-
-
-# Mouse events for Area
-func _on_area_input_event(_camera, event, click_pos, _click_normal, _shape_idx):
-	# Use click pos (click in 3d space, convert to area space)
-	var pos = get_node("Area").get_global_transform().affine_inverse()
-	# the click pos is not zero, then use it to convert from 3D space to area space
-	if click_pos.x != 0 or click_pos.y != 0 or click_pos.z != 0:
-		pos *= click_pos
-		last_click_pos = click_pos
+	
+	# If the event is a mouse/touch event and/or the mouse is either held or inside the area, then
+	# we need to do some additional processing in the handle_mouse function before passing the event to the viewport.
+	# If the event is not a mouse/touch event, then we can just pass the event directly to the viewport.
+	if is_mouse_event and (is_mouse_inside or is_mouse_held):
+		handle_mouse(event)
+	elif not is_mouse_event:
+		node_viewport.input(event)
+
+
+# Handle mouse events inside Area. (Area.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
+	
+	# Detect mouse being held to mantain event while outside of bounds. Avoid orphan clicks
+	if event is InputEventMouseButton or event is InputEventScreenTouch:
+		is_mouse_held = event.pressed
+	
+	# Find mouse position in Area
+	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!
+		mouse_pos3D = node_area.global_transform.affine_inverse() * mouse_pos3D
+		last_mouse_pos3D = mouse_pos3D
 	else:
 	else:
-		# Otherwise, we have a motion event and need to use our last click pos
-		# and move it according to the relative position of the event.
-		# NOTE: this is not an exact 1-1 conversion, but it's pretty close
-		pos *= last_click_pos
-		if event is InputEventMouseMotion or event is InputEventScreenDrag:
-			pos.x += event.relative.x / viewport.size.x
-			pos.y += event.relative.y / viewport.size.y
-			last_click_pos = pos
-  
-	# Convert to 2D
-	pos = Vector2(pos.x, pos.y)
-  
-	# Convert to viewport coordinate system
-	# Convert pos to a range from (0 - 1)
-	pos.y *= -1
-	pos += Vector2(1, 1)
-	pos = pos / 2
-  
-	# Convert pos to be in range of the viewport
-	pos.x *= viewport.size.x
-	pos.y *= viewport.size.y
-	
-	# Set the position in event
-	event.position = pos
-	event.global_position = pos
-	if not prev_pos:
-		prev_pos = pos
+		mouse_pos3D = last_mouse_pos3D
+		if mouse_pos3D == null:
+			mouse_pos3D = Vector3.ZERO
+	
+	# TODO: adapt to bilboard mode or avoid completely
+	
+	# convert the relative event position from 3D to 2D
+	var mouse_pos2D = Vector2(mouse_pos3D.x, -mouse_pos3D.y)
+	
+	# Right now the event position's range is the following: (-quad_size/2) -> (quad_size/2)
+	# We need to convert it into the following range: 0 -> quad_size
+	mouse_pos2D.x += quad_mesh_size.x / 2
+	mouse_pos2D.y += quad_mesh_size.y / 2
+	# Then we need to convert it into the following range: 0 -> 1
+	mouse_pos2D.x = mouse_pos2D.x / quad_mesh_size.x
+	mouse_pos2D.y = mouse_pos2D.y / quad_mesh_size.y
+	
+	# Finally, we convert the position to the following range: 0 -> viewport.size
+	mouse_pos2D.x = mouse_pos2D.x * node_viewport.size.x
+	mouse_pos2D.y = mouse_pos2D.y * node_viewport.size.y
+	# We need to do these conversions so the event's position is in the viewport's coordinate system.
+	
+	# Set the event's position and global position.
+	event.position = mouse_pos2D
+	event.global_position = mouse_pos2D
+	
+	# If the event is a mouse motion event...
 	if event is InputEventMouseMotion:
 	if event is InputEventMouseMotion:
-		event.relative = pos - prev_pos
-	prev_pos = pos
+		# If there is not a stored previous position, then we'll assume there is no relative motion.
+		if last_mouse_pos2D == null:
+			event.relative = Vector2(0, 0)
+		# If there is a stored previous position, then we'll calculate the relative position by subtracting
+		# the previous position from the new position. This will give us the distance the event traveled from prev_pos
+		else:
+			event.relative = mouse_pos2D - last_mouse_pos2D
+	# Update last_mouse_pos2D with the position we just calculated.
+	last_mouse_pos2D = mouse_pos2D
 	
 	
-	# Send the event to the viewport
-	viewport.input(event)
+	# Finally, send the processed input event to the viewport.
+	node_viewport.input(event)
 
 
 
 
-func _ready():
-	viewport = get_node("Viewport")
-	get_node("Area").connect("input_event", self, "_on_area_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 dist = find_further_distance_to(camera.transform.origin)
+	var to = 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
+	
+	if result.size() > 0:
+		return result.position
+	else:
+		return null
+
+
+func find_further_distance_to(origin):
+	# Find edges of collision and change to global positions
+	var edges = []
+	edges.append(node_area.to_global(Vector3(quad_mesh_size.x / 2, quad_mesh_size.y / 2, 0)))
+	edges.append(node_area.to_global(Vector3(quad_mesh_size.x / 2, -quad_mesh_size.y / 2, 0)))
+	edges.append(node_area.to_global(Vector3(-quad_mesh_size.x / 2, quad_mesh_size.y / 2, 0)))
+	edges.append(node_area.to_global(Vector3(-quad_mesh_size.x / 2, -quad_mesh_size.y / 2, 0)))
+	
+	# Get the furthest distance between the camera and collision to avoid raycasting too far or too short
+	var far_dist = 0
+	var temp_dist
+	for edge in edges:
+		temp_dist = origin.distance_to(edge)
+		if temp_dist > far_dist:
+			far_dist = temp_dist
+	
+	return far_dist
+
+
+func rotate_area_to_billboard():
+	var billboard_mode = node_quad.get_surface_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()
+		# 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
+		
+		# Y-Billboard: Lock Y rotation, but gives bad results if the camera is tilted.
+		if billboard_mode == 2: 
+			look = Vector3(look.x, 0, look.z)
+		
+		node_area.look_at(look, Vector3.UP)
+		
+		# Rotate in the Z axis to compensate camera tilt
+		node_area.rotate_object_local(Vector3.BACK, camera.rotation.z)
+

+ 119 - 0
viewport/gui_in_3d/gui_in_3d.tscn

@@ -0,0 +1,119 @@
+[gd_scene load_steps=10 format=2]
+
+[ext_resource path="res://view_gui.tscn" type="PackedScene" id=1]
+
+[sub_resource type="Animation" id=1]
+length = 6.0
+loop = true
+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/keys = {
+"times": PoolRealArray( 0, 2, 4, 6 ),
+"transitions": PoolRealArray( 1, 1, 1, 1 ),
+"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 ) ]
+}
+
+[sub_resource type="PlaneMesh" id=2]
+
+[sub_resource type="GDScript" id=3]
+script/source = "tool
+extends Object
+func e():
+	return 0
+"
+
+[sub_resource type="GDScript" id=4]
+script/source = "tool
+extends Object
+func e():
+	return 90
+"
+
+[sub_resource type="GDScript" id=5]
+script/source = "tool
+extends Object
+func e():
+	return 0
+"
+
+[sub_resource type="CubeMesh" id=6]
+
+[sub_resource type="SpatialMaterial" id=7]
+albedo_color = Color( 0.722656, 0.791992, 1, 1 )
+roughness = 0.0
+
+[sub_resource type="GDScript" id=8]
+script/source = "tool
+extends Object
+func e():
+	return 0
+"
+
+[node name="gui_in_3d" type="Spatial"]
+
+[node name="view_gui" parent="." instance=ExtResource( 1 )]
+
+[node name="Camera" type="Camera" parent="."]
+transform = Transform( 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 )
+shadow_enabled = true
+omni_range = 10.0
+
+[node name="Camera_Move" type="AnimationPlayer" parent="."]
+autoplay = "Move_camera"
+playback_speed = 0.25
+anims/Move_camera = SubResource( 1 )
+
+[node name="3D_background" type="Spatial" parent="."]
+editor/display_folded = true
+
+[node name="Wall" type="MeshInstance" parent="3D_background"]
+transform = Transform( 4, 0, 0, 0, -1.74846e-007, -4, 0, 4, -1.74846e-007, -2.60819, 0.589247, -2.08943 )
+mesh = SubResource( 2 )
+material/0 = null
+script = SubResource( 3 )
+
+[node name="Wall2" type="MeshInstance" parent="3D_background"]
+transform = Transform( 4, 0, 0, 0, -1.74846e-007, -4, 0, 4, -1.74846e-007, 5.08055, 0.589247, -2.08943 )
+mesh = SubResource( 2 )
+material/0 = null
+script = SubResource( 3 )
+
+[node name="Wall3" type="MeshInstance" parent="3D_background"]
+transform = Transform( -1.74846e-007, -4, 0, -1.74846e-007, 7.64274e-015, -4, 4, -1.74846e-007, -1.74846e-007, 9.04446, 0.589247, 1.62058 )
+mesh = SubResource( 2 )
+material/0 = null
+script = SubResource( 4 )
+
+[node name="Floor" type="MeshInstance" parent="3D_background"]
+transform = Transform( 4, 0, 0, 0, 4, 0, 0, 0, 4, -2.60819, -2.68765, 1.46502 )
+mesh = SubResource( 2 )
+material/0 = null
+script = SubResource( 5 )
+
+[node name="Floor2" type="MeshInstance" parent="3D_background"]
+transform = Transform( 4, 0, 0, 0, 4, 0, 0, 0, 4, 5.08055, -2.68765, 1.46502 )
+mesh = SubResource( 2 )
+material/0 = null
+script = SubResource( 5 )
+
+[node name="Cube" type="MeshInstance" parent="3D_background"]
+transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 4.25901, -0.598608, 0.374871 )
+mesh = SubResource( 6 )
+material/0 = SubResource( 7 )
+script = SubResource( 8 )
+
+[node name="Cube2" type="MeshInstance" parent="3D_background"]
+transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 2.88761, 2.01326, 0.374871 )
+mesh = SubResource( 6 )
+material/0 = SubResource( 7 )
+script = SubResource( 8 )

+ 5 - 3
viewport/gui_in_3d/icon.png.import

@@ -3,20 +3,21 @@
 importer="texture"
 importer="texture"
 type="StreamTexture"
 type="StreamTexture"
 path="res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex"
 path="res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex"
+metadata={
+"vram_texture": false
+}
 
 
 [deps]
 [deps]
 
 
 source_file="res://icon.png"
 source_file="res://icon.png"
-source_md5="434c8eb4c3320b4afd88f7a34b3a12d6"
-
 dest_files=[ "res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex" ]
 dest_files=[ "res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex" ]
-dest_md5="a6b3d106eb33d75fd3532a8554f6daaa"
 
 
 [params]
 [params]
 
 
 compress/mode=0
 compress/mode=0
 compress/lossy_quality=0.7
 compress/lossy_quality=0.7
 compress/hdr_mode=0
 compress/hdr_mode=0
+compress/bptc_ldr=0
 compress/normal_map=0
 compress/normal_map=0
 flags/repeat=0
 flags/repeat=0
 flags/filter=true
 flags/filter=true
@@ -26,6 +27,7 @@ flags/srgb=2
 process/fix_alpha_border=true
 process/fix_alpha_border=true
 process/premult_alpha=false
 process/premult_alpha=false
 process/HDR_as_SRGB=false
 process/HDR_as_SRGB=false
+process/invert_color=false
 stream=false
 stream=false
 size_limit=0
 size_limit=0
 detect_3d=true
 detect_3d=true

+ 5 - 5
viewport/gui_in_3d/project.godot

@@ -16,17 +16,17 @@ _global_script_class_icons={
 [application]
 [application]
 
 
 config/name="GUI in 3D"
 config/name="GUI in 3D"
-run/main_scene="res://Gui_in_3D.tscn"
+run/main_scene="res://gui_in_3d.tscn"
 config/icon="res://icon.png"
 config/icon="res://icon.png"
 
 
-[debug]
-
-gdscript/warnings/return_value_discarded=false
-
 [gdnative]
 [gdnative]
 
 
 singletons=[  ]
 singletons=[  ]
 
 
+[layer_names]
+
+3d_physics/layer_2="Control"
+
 [rendering]
 [rendering]
 
 
 environment/default_environment="res://default_env.tres"
 environment/default_environment="res://default_env.tres"

+ 113 - 0
viewport/gui_in_3d/view_gui.tscn

@@ -0,0 +1,113 @@
+[gd_scene load_steps=7 format=2]
+
+[ext_resource path="res://gui_3d.gd" type="Script" id=1]
+[ext_resource path="res://icon.png" type="Texture" id=2]
+
+[sub_resource type="QuadMesh" id=1]
+size = Vector2( 3, 2 )
+
+[sub_resource type="ViewportTexture" id=2]
+viewport_path = NodePath("Viewport")
+
+[sub_resource type="SpatialMaterial" id=3]
+resource_local_to_scene = true
+flags_transparent = true
+flags_unshaded = true
+flags_albedo_tex_force_srgb = true
+albedo_texture = SubResource( 2 )
+
+[sub_resource type="BoxShape" id=4]
+extents = Vector3( 1.5, 1, 0.05 )
+
+[node name="GUI_3D" type="Spatial"]
+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="GUI" type="Control" parent="Viewport"]
+editor/display_folded = true
+margin_right = 280.0
+margin_bottom = 180.0
+mouse_filter = 1
+
+[node name="Panel" type="Panel" parent="Viewport/GUI"]
+anchor_right = 1.0
+anchor_bottom = 1.0
+
+[node name="Label" type="Label" parent="Viewport/GUI/Panel"]
+margin_left = 44.0
+margin_top = 27.0
+margin_right = 121.0
+margin_bottom = 41.0
+text = "Hello world!"
+
+[node name="Button" type="Button" parent="Viewport/GUI/Panel"]
+margin_left = 14.0
+margin_top = 46.0
+margin_right = 154.0
+margin_bottom = 74.0
+text = "A button!"
+
+[node name="TextEdit" type="LineEdit" parent="Viewport/GUI/Panel"]
+margin_left = 14.0
+margin_top = 87.0
+margin_right = 154.0
+margin_bottom = 111.0
+
+[node name="HSlider" type="HSlider" parent="Viewport/GUI/Panel"]
+margin_left = 14.0
+margin_top = 118.0
+margin_right = 154.0
+margin_bottom = 143.0
+ticks_on_borders = true
+
+[node name="ColorRect" type="ColorRect" parent="Viewport/GUI/Panel"]
+margin_left = 180.0
+margin_top = 26.0
+margin_right = 244.0
+margin_bottom = 90.0
+color = Color( 1, 0, 0, 1 )
+
+[node name="TextureRect" type="TextureRect" parent="Viewport/GUI/Panel"]
+anchor_left = 0.5
+anchor_top = 0.5
+anchor_right = 0.5
+anchor_bottom = 0.5
+margin_left = 52.0
+margin_top = -52.0
+margin_right = 92.0
+margin_bottom = -12.0
+texture = ExtResource( 2 )
+expand = true
+
+[node name="VSlider" type="VSlider" parent="Viewport/GUI/Panel"]
+margin_left = 260.0
+margin_top = 26.0
+margin_right = 276.0
+margin_bottom = 166.0
+ticks_on_borders = false
+
+[node name="OptionButton" type="OptionButton" parent="Viewport/GUI/Panel"]
+margin_left = 170.0
+margin_top = 111.0
+margin_right = 252.0
+margin_bottom = 165.0
+text = "Item 0"
+items = [ "Item 0", null, false, -1, null, "Item 1", null, false, -1, null, "Item 2", null, false, -1, null ]
+selected = 0
+
+[node name="Quad" type="MeshInstance" parent="."]
+mesh = SubResource( 1 )
+material/0 = SubResource( 3 )
+
+[node name="Area" type="Area" parent="Quad"]
+input_capture_on_drag = true
+collision_layer = 2
+
+[node name="CollisionShape" type="CollisionShape" parent="Quad/Area"]
+shape = SubResource( 4 )