Browse Source

Merge pull request #393 from aaronfranke/viewport

Update remaining Viewport demos to Godot 3.1.2
Aaron Franke 5 years ago
parent
commit
691f1d94d6

+ 18 - 18
viewport/3d_in_2d/3D_in_2D.gd → viewport/3d_in_2d/3d_in_2d.gd

@@ -1,38 +1,37 @@
 extends Node2D
 extends Node2D
 
 
-# Member variables
-var viewport = null
-var sprite = null
-var viewport_sprite = null
-
-var viewport_initial_size = Vector2()
-
-# variables for the sprite animation
+# These first 3 members are for the sprite animation.
 const MAX_FRAME_FOR_SPRITE = 4
 const MAX_FRAME_FOR_SPRITE = 4
 const FRAME_SWITCH_TIME = 0.2
 const FRAME_SWITCH_TIME = 0.2
+
 var frame_switch_timer = 0
 var frame_switch_timer = 0
+var viewport_initial_size = Vector2()
+
+onready var viewport = $Viewport
+onready var sprite = $Sprite2D
+onready var viewport_sprite = $ViewportSprite
 
 
 func _ready():
 func _ready():
+	# We want Godot to load everything but be hidden for a bit.
+	viewport_sprite.modulate = Color(1, 1, 1, 0.01)
+	#warning-ignore:return_value_discarded
 	get_viewport().connect("size_changed", self, "_root_viewport_size_changed")
 	get_viewport().connect("size_changed", self, "_root_viewport_size_changed")
-
-	viewport = get_node("Viewport")
-	sprite = get_node("Sprite")
-	viewport_sprite = get_node("Viewport_Sprite")
-
 	viewport_initial_size = viewport.size
 	viewport_initial_size = viewport.size
 
 
-	# Assign the sprite's texture to the viewport texture
+	# Assign the sprite's texture to the viewport texture.
 	viewport.set_clear_mode(Viewport.CLEAR_MODE_ONLY_NEXT_FRAME)
 	viewport.set_clear_mode(Viewport.CLEAR_MODE_ONLY_NEXT_FRAME)
 
 
-	# Let two frames pass to make sure the screen was captured
+	# Let two frames pass to make sure the screen was captured.
 	yield(get_tree(), "idle_frame")
 	yield(get_tree(), "idle_frame")
 	yield(get_tree(), "idle_frame")
 	yield(get_tree(), "idle_frame")
 	viewport_sprite.texture = viewport.get_texture()
 	viewport_sprite.texture = viewport.get_texture()
+	# Hide a little bit longer just in case.
+	for _unused in range(50):
+		yield(get_tree(), "idle_frame")
+	viewport_sprite.modulate = Color.white # Default modulate color.
 
 
-	set_process(true)
 
 
-
-# Simple frame-based animation
+# Simple frame-based animation.
 func _process(delta):
 func _process(delta):
 	frame_switch_timer += delta
 	frame_switch_timer += delta
 	if frame_switch_timer >= FRAME_SWITCH_TIME:
 	if frame_switch_timer >= FRAME_SWITCH_TIME:
@@ -41,6 +40,7 @@ func _process(delta):
 	if sprite.frame > MAX_FRAME_FOR_SPRITE:
 	if sprite.frame > MAX_FRAME_FOR_SPRITE:
 		sprite.frame = 0
 		sprite.frame = 0
 
 
+
 # Called when the root's viewport size changes (i.e. when the window is resized).
 # Called when the root's viewport size changes (i.e. when the window is resized).
 # This is done to handle multiple resolutions without losing quality.
 # This is done to handle multiple resolutions without losing quality.
 func _root_viewport_size_changed():
 func _root_viewport_size_changed():

+ 7 - 12
viewport/3d_in_2d/3D_in_2D.tscn → viewport/3d_in_2d/3d_in_2d.tscn

@@ -1,13 +1,13 @@
 [gd_scene load_steps=4 format=2]
 [gd_scene load_steps=4 format=2]
 
 
-[ext_resource path="res://player.scn" type="PackedScene" id=1]
+[ext_resource path="res://3d_in_2d.gd" type="Script" id=1]
 [ext_resource path="res://robot_demo.png" type="Texture" id=2]
 [ext_resource path="res://robot_demo.png" type="Texture" id=2]
-[ext_resource path="res://3D_in_2D.gd" type="Script" id=3]
+[ext_resource path="res://robot_3d.tscn" type="PackedScene" id=3]
 
 
-[node name="3D_in_2D" type="Node2D"]
-script = ExtResource( 3 )
+[node name="3Din2D" type="Node2D"]
+script = ExtResource( 1 )
 
 
-[node name="Sprite" type="Sprite" parent="."]
+[node name="Sprite2D" type="Sprite" parent="."]
 position = Vector2( 339.942, 311.204 )
 position = Vector2( 339.942, 311.204 )
 scale = Vector2( 3, 3 )
 scale = Vector2( 3, 3 )
 texture = ExtResource( 2 )
 texture = ExtResource( 2 )
@@ -15,7 +15,7 @@ vframes = 2
 hframes = 16
 hframes = 16
 frame = 4
 frame = 4
 
 
-[node name="Viewport_Sprite" type="Sprite" parent="."]
+[node name="ViewportSprite" type="Sprite" parent="."]
 position = Vector2( 600, 320 )
 position = Vector2( 600, 320 )
 rotation = 3.14159
 rotation = 3.14159
 
 
@@ -27,13 +27,8 @@ msaa = 2
 hdr = false
 hdr = false
 usage = 3
 usage = 3
 
 
-[node name="player" parent="Viewport" instance=ExtResource( 1 )]
-
-[node name="Camera" parent="Viewport/player" index="1"]
-current = true
+[node name="Robot3D" parent="Viewport" instance=ExtResource( 3 )]
 
 
 [node name="Camera2D" type="Camera2D" parent="."]
 [node name="Camera2D" type="Camera2D" parent="."]
 offset = Vector2( 512, 300 )
 offset = Vector2( 512, 300 )
 current = true
 current = true
-
-[editable path="Viewport/player"]

+ 0 - 14
viewport/3d_in_2d/player.gd

@@ -1,14 +0,0 @@
-extends KinematicBody
-
-# A simple program to rotate the model around
-
-var model = null
-const SPEED = 40
-
-func _ready():
-	model = get_node("Armature")
-	set_process(true)
-
-
-func _process(delta):
-	model.rotation_degrees.y += delta * SPEED

BIN
viewport/3d_in_2d/player.scn


+ 1 - 1
viewport/3d_in_2d/project.godot

@@ -16,7 +16,7 @@ _global_script_class_icons={
 [application]
 [application]
 
 
 config/name="3D in 2D"
 config/name="3D in 2D"
-run/main_scene="res://3D_in_2D.tscn"
+run/main_scene="res://3d_in_2d.tscn"
 config/icon="res://icon.png"
 config/icon="res://icon.png"
 
 
 [display]
 [display]

+ 8 - 0
viewport/3d_in_2d/robot_3d.gd

@@ -0,0 +1,8 @@
+extends KinematicBody
+
+# A simple script to rotate the model.
+onready var model = $Armature
+const SPEED = 40
+
+func _process(delta):
+	model.rotation_degrees.y += delta * SPEED

File diff suppressed because it is too large
+ 23 - 0
viewport/3d_in_2d/robot_3d.tscn


+ 2 - 4
viewport/gui_in_3d/gui_3d.gd

@@ -1,5 +1,5 @@
 extends Spatial
 extends Spatial
-# Member variables
+
 # The size of the quad mesh itself.
 # The size of the quad mesh itself.
 var quad_mesh_size
 var quad_mesh_size
 # Used for checking if the mouse is inside the Area
 # Used for checking if the mouse is inside the Area
@@ -10,12 +10,11 @@ var is_mouse_held = false
 var last_mouse_pos3D = null
 var last_mouse_pos3D = null
 # The last processed input touch/mouse event. To calculate relative movement.
 # The last processed input touch/mouse event. To calculate relative movement.
 var last_mouse_pos2D = null
 var last_mouse_pos2D = null
-# Most used nodes
+
 onready var node_viewport = $Viewport
 onready var node_viewport = $Viewport
 onready var node_quad = $Quad
 onready var node_quad = $Quad
 onready var node_area = $Quad/Area
 onready var node_area = $Quad/Area
 
 
-
 func _ready():
 func _ready():
 	node_area.connect("mouse_entered", self, "_mouse_entered_area")
 	node_area.connect("mouse_entered", self, "_mouse_entered_area")
 	
 	
@@ -169,4 +168,3 @@ func rotate_area_to_billboard():
 		
 		
 		# Rotate in the Z axis to compensate camera tilt
 		# Rotate in the Z axis to compensate camera tilt
 		node_area.rotate_object_local(Vector3.BACK, camera.rotation.z)
 		node_area.rotate_object_local(Vector3.BACK, camera.rotation.z)
-

+ 22 - 57
viewport/gui_in_3d/gui_in_3d.tscn

@@ -1,6 +1,6 @@
-[gd_scene load_steps=10 format=2]
+[gd_scene load_steps=6 format=2]
 
 
-[ext_resource path="res://view_gui.tscn" type="PackedScene" id=1]
+[ext_resource path="res://gui_panel_3d.tscn" type="PackedScene" id=1]
 
 
 [sub_resource type="Animation" id=1]
 [sub_resource type="Animation" id=1]
 length = 6.0
 length = 6.0
@@ -20,43 +20,15 @@ tracks/0/keys = {
 
 
 [sub_resource type="PlaneMesh" id=2]
 [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]
+[sub_resource type="CubeMesh" id=3]
+
+[sub_resource type="SpatialMaterial" id=4]
 albedo_color = Color( 0.722656, 0.791992, 1, 1 )
 albedo_color = Color( 0.722656, 0.791992, 1, 1 )
 roughness = 0.0
 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="GUIin3D" type="Spatial"]
 
 
-[node name="view_gui" parent="." instance=ExtResource( 1 )]
+[node name="GUIPanel3D" parent="." instance=ExtResource( 1 )]
 
 
 [node name="Camera" type="Camera" parent="."]
 [node name="Camera" type="Camera" parent="."]
 transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 0.999999, 0, 0, 3 )
 transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 0.999999, 0, 0, 3 )
@@ -73,46 +45,39 @@ autoplay = "Move_camera"
 playback_speed = 0.25
 playback_speed = 0.25
 anims/Move_camera = SubResource( 1 )
 anims/Move_camera = SubResource( 1 )
 
 
-[node name="3D_background" type="Spatial" parent="."]
+[node name="Background" type="Spatial" parent="."]
 
 
-[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 )
+[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 )
 mesh = SubResource( 2 )
 material/0 = null
 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 )
+[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 )
 mesh = SubResource( 2 )
 material/0 = null
 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 )
+[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 )
 mesh = SubResource( 2 )
 material/0 = null
 material/0 = null
-script = SubResource( 4 )
 
 
-[node name="Floor" type="MeshInstance" parent="3D_background"]
+[node name="Floor" type="MeshInstance" parent="Background"]
 transform = Transform( 4, 0, 0, 0, 4, 0, 0, 0, 4, -2.60819, -2.68765, 1.46502 )
 transform = Transform( 4, 0, 0, 0, 4, 0, 0, 0, 4, -2.60819, -2.68765, 1.46502 )
 mesh = SubResource( 2 )
 mesh = SubResource( 2 )
 material/0 = null
 material/0 = null
-script = SubResource( 5 )
 
 
-[node name="Floor2" type="MeshInstance" parent="3D_background"]
+[node name="Floor2" type="MeshInstance" parent="Background"]
 transform = Transform( 4, 0, 0, 0, 4, 0, 0, 0, 4, 5.08055, -2.68765, 1.46502 )
 transform = Transform( 4, 0, 0, 0, 4, 0, 0, 0, 4, 5.08055, -2.68765, 1.46502 )
 mesh = SubResource( 2 )
 mesh = SubResource( 2 )
 material/0 = null
 material/0 = null
-script = SubResource( 5 )
 
 
-[node name="Cube" type="MeshInstance" parent="3D_background"]
+[node name="Cube" type="MeshInstance" parent="Background"]
 transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 4.25901, -0.598608, 0.374871 )
 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 )
+mesh = SubResource( 3 )
+material/0 = SubResource( 4 )
 
 
-[node name="Cube2" type="MeshInstance" parent="3D_background"]
+[node name="Cube2" type="MeshInstance" parent="Background"]
 transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 2.88761, 2.01326, 0.374871 )
 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 )
+mesh = SubResource( 3 )
+material/0 = SubResource( 4 )

+ 2 - 3
viewport/gui_in_3d/view_gui.tscn → viewport/gui_in_3d/gui_panel_3d.tscn

@@ -19,7 +19,7 @@ albedo_texture = SubResource( 2 )
 [sub_resource type="BoxShape" id=4]
 [sub_resource type="BoxShape" id=4]
 extents = Vector3( 1.5, 1, 0.05 )
 extents = Vector3( 1.5, 1, 0.05 )
 
 
-[node name="GUI_3D" type="Spatial"]
+[node name="GUIPanel3D" type="Spatial"]
 script = ExtResource( 1 )
 script = ExtResource( 1 )
 
 
 [node name="Viewport" type="Viewport" parent="."]
 [node name="Viewport" type="Viewport" parent="."]
@@ -89,7 +89,6 @@ margin_left = 260.0
 margin_top = 26.0
 margin_top = 26.0
 margin_right = 276.0
 margin_right = 276.0
 margin_bottom = 166.0
 margin_bottom = 166.0
-ticks_on_borders = false
 
 
 [node name="OptionButton" type="OptionButton" parent="Viewport/GUI/Panel"]
 [node name="OptionButton" type="OptionButton" parent="Viewport/GUI/Panel"]
 margin_left = 170.0
 margin_left = 170.0
@@ -97,7 +96,7 @@ margin_top = 111.0
 margin_right = 252.0
 margin_right = 252.0
 margin_bottom = 165.0
 margin_bottom = 165.0
 text = "Item 0"
 text = "Item 0"
-items = [ "Item 0", null, false, -1, null, "Item 1", null, false, -1, null, "Item 2", null, false, -1, null ]
+items = [ "Item 0", null, false, 0, null, "Item 1", null, false, 1, null, "Item 2", null, false, 2, null ]
 selected = 0
 selected = 0
 
 
 [node name="Quad" type="MeshInstance" parent="."]
 [node name="Quad" type="MeshInstance" parent="."]

+ 1 - 1
viewport/screen_capture/project.godot

@@ -16,7 +16,7 @@ _global_script_class_icons={
 [application]
 [application]
 
 
 config/name="Screen Capture"
 config/name="Screen Capture"
-run/main_scene="res://capture_screen.tscn"
+run/main_scene="res://screen_capture.tscn"
 config/icon="res://icon.png"
 config/icon="res://icon.png"
 
 
 [debug]
 [debug]

+ 9 - 13
viewport/screen_capture/screen_capture.gd

@@ -1,26 +1,22 @@
+extends Node
 
 
-extends Control
+onready var captured_image = $CapturedImage
 
 
-
-func _ready():
-	get_node("Button").connect("pressed", self, "_on_button_pressed");
-
-
-func _on_button_pressed():
+func _on_CaptureButton_pressed():
 	get_viewport().set_clear_mode(Viewport.CLEAR_MODE_ONLY_NEXT_FRAME)
 	get_viewport().set_clear_mode(Viewport.CLEAR_MODE_ONLY_NEXT_FRAME)
-	# Let two frames pass to make sure the screen was captured
+	# Let two frames pass to make sure the screen was captured.
 	yield(get_tree(), "idle_frame")
 	yield(get_tree(), "idle_frame")
 	yield(get_tree(), "idle_frame")
 	yield(get_tree(), "idle_frame")
 
 
-	# Retrieve the captured image
+	# Retrieve the captured image.
 	var img = get_viewport().get_texture().get_data()
 	var img = get_viewport().get_texture().get_data()
 
 
-	# Flip it on the y-axis (because it's flipped)
+	# Flip it on the y-axis (because it's flipped).
 	img.flip_y()
 	img.flip_y()
 
 
-	# Create a texture for it
+	# Create a texture for it.
 	var tex = ImageTexture.new()
 	var tex = ImageTexture.new()
 	tex.create_from_image(img)
 	tex.create_from_image(img)
 
 
-	# Set it to the capture node
-	get_node("capture").set_texture(tex)
+	# Set the texture to the captured image node.
+	captured_image.set_texture(tex)

+ 5 - 4
viewport/screen_capture/capture_screen.tscn → viewport/screen_capture/screen_capture.tscn

@@ -3,12 +3,12 @@
 [ext_resource path="res://screen_capture.gd" type="Script" id=1]
 [ext_resource path="res://screen_capture.gd" type="Script" id=1]
 [ext_resource path="res://mountains.png" type="Texture" id=2]
 [ext_resource path="res://mountains.png" type="Texture" id=2]
 
 
-[node name="Control" type="Control"]
+[node name="ScreenCapture" type="Control"]
 margin_right = 40.0
 margin_right = 40.0
 margin_bottom = 40.0
 margin_bottom = 40.0
 script = ExtResource( 1 )
 script = ExtResource( 1 )
 
 
-[node name="BG" type="TextureRect" parent="."]
+[node name="Background" type="TextureRect" parent="."]
 anchor_right = 1.0
 anchor_right = 1.0
 anchor_bottom = 1.0
 anchor_bottom = 1.0
 margin_right = 986.0
 margin_right = 986.0
@@ -18,7 +18,7 @@ grow_vertical = 0
 texture = ExtResource( 2 )
 texture = ExtResource( 2 )
 expand = true
 expand = true
 
 
-[node name="capture" type="TextureRect" parent="."]
+[node name="CapturedImage" type="TextureRect" parent="."]
 anchor_right = 1.0
 anchor_right = 1.0
 anchor_bottom = 1.0
 anchor_bottom = 1.0
 margin_right = 2013.0
 margin_right = 2013.0
@@ -29,9 +29,10 @@ rect_scale = Vector2( 0.5, 0.5 )
 expand = true
 expand = true
 stretch_mode = 4
 stretch_mode = 4
 
 
-[node name="Button" type="Button" parent="."]
+[node name="CaptureButton" type="Button" parent="."]
 margin_left = 48.0
 margin_left = 48.0
 margin_top = 53.0
 margin_top = 53.0
 margin_right = 188.0
 margin_right = 188.0
 margin_bottom = 113.0
 margin_bottom = 113.0
 text = "Capture screen"
 text = "Capture screen"
+[connection signal="pressed" from="CaptureButton" to="." method="_on_CaptureButton_pressed"]

Some files were not shown because too many files changed in this diff