mirror of
https://github.com/godotengine/godot-demo-projects.git
synced 2026-01-04 23:10:08 +01:00
Merge pull request #393 from aaronfranke/viewport
Update remaining Viewport demos to Godot 3.1.2
This commit is contained in:
@@ -1,38 +1,37 @@
|
||||
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 FRAME_SWITCH_TIME = 0.2
|
||||
|
||||
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():
|
||||
# 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")
|
||||
|
||||
viewport = get_node("Viewport")
|
||||
sprite = get_node("Sprite")
|
||||
viewport_sprite = get_node("Viewport_Sprite")
|
||||
|
||||
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)
|
||||
|
||||
# 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")
|
||||
viewport_sprite.texture = viewport.get_texture()
|
||||
|
||||
set_process(true)
|
||||
# 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.
|
||||
|
||||
|
||||
# Simple frame-based animation
|
||||
# Simple frame-based animation.
|
||||
func _process(delta):
|
||||
frame_switch_timer += delta
|
||||
if frame_switch_timer >= FRAME_SWITCH_TIME:
|
||||
@@ -41,6 +40,7 @@ func _process(delta):
|
||||
if sprite.frame > MAX_FRAME_FOR_SPRITE:
|
||||
sprite.frame = 0
|
||||
|
||||
|
||||
# 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.
|
||||
func _root_viewport_size_changed():
|
||||
@@ -1,13 +1,13 @@
|
||||
[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://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 )
|
||||
scale = Vector2( 3, 3 )
|
||||
texture = ExtResource( 2 )
|
||||
@@ -15,7 +15,7 @@ vframes = 2
|
||||
hframes = 16
|
||||
frame = 4
|
||||
|
||||
[node name="Viewport_Sprite" type="Sprite" parent="."]
|
||||
[node name="ViewportSprite" type="Sprite" parent="."]
|
||||
position = Vector2( 600, 320 )
|
||||
rotation = 3.14159
|
||||
|
||||
@@ -27,13 +27,8 @@ msaa = 2
|
||||
hdr = false
|
||||
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="."]
|
||||
offset = Vector2( 512, 300 )
|
||||
current = true
|
||||
|
||||
[editable path="Viewport/player"]
|
||||
@@ -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
|
||||
Binary file not shown.
@@ -16,7 +16,7 @@ _global_script_class_icons={
|
||||
[application]
|
||||
|
||||
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"
|
||||
|
||||
[display]
|
||||
|
||||
8
viewport/3d_in_2d/robot_3d.gd
Normal file
8
viewport/3d_in_2d/robot_3d.gd
Normal file
@@ -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
|
||||
238
viewport/3d_in_2d/robot_3d.tscn
Normal file
238
viewport/3d_in_2d/robot_3d.tscn
Normal file
File diff suppressed because one or more lines are too long
@@ -1,5 +1,5 @@
|
||||
extends Spatial
|
||||
# Member variables
|
||||
|
||||
# The size of the quad mesh itself.
|
||||
var quad_mesh_size
|
||||
# Used for checking if the mouse is inside the Area
|
||||
@@ -10,12 +10,11 @@ var is_mouse_held = false
|
||||
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")
|
||||
|
||||
@@ -169,4 +168,3 @@ func rotate_area_to_billboard():
|
||||
|
||||
# Rotate in the Z axis to compensate camera tilt
|
||||
node_area.rotate_object_local(Vector3.BACK, camera.rotation.z)
|
||||
|
||||
|
||||
@@ -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]
|
||||
length = 6.0
|
||||
@@ -20,43 +20,15 @@ tracks/0/keys = {
|
||||
|
||||
[sub_resource type="PlaneMesh" id=2]
|
||||
|
||||
[sub_resource type="GDScript" id=3]
|
||||
script/source = "tool
|
||||
extends Object
|
||||
func e():
|
||||
return 0
|
||||
"
|
||||
[sub_resource type="CubeMesh" id=3]
|
||||
|
||||
[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="SpatialMaterial" id=4]
|
||||
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="GUIin3D" type="Spatial"]
|
||||
|
||||
[node name="gui_in_3d" type="Spatial"]
|
||||
|
||||
[node name="view_gui" parent="." instance=ExtResource( 1 )]
|
||||
[node name="GUIPanel3D" 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 )
|
||||
@@ -73,46 +45,39 @@ autoplay = "Move_camera"
|
||||
playback_speed = 0.25
|
||||
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 )
|
||||
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 )
|
||||
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 )
|
||||
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 )
|
||||
mesh = SubResource( 2 )
|
||||
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 )
|
||||
mesh = SubResource( 2 )
|
||||
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 )
|
||||
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 )
|
||||
mesh = SubResource( 6 )
|
||||
material/0 = SubResource( 7 )
|
||||
script = SubResource( 8 )
|
||||
mesh = SubResource( 3 )
|
||||
material/0 = SubResource( 4 )
|
||||
|
||||
@@ -19,7 +19,7 @@ albedo_texture = SubResource( 2 )
|
||||
[sub_resource type="BoxShape" id=4]
|
||||
extents = Vector3( 1.5, 1, 0.05 )
|
||||
|
||||
[node name="GUI_3D" type="Spatial"]
|
||||
[node name="GUIPanel3D" type="Spatial"]
|
||||
script = ExtResource( 1 )
|
||||
|
||||
[node name="Viewport" type="Viewport" parent="."]
|
||||
@@ -89,7 +89,6 @@ 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
|
||||
@@ -97,7 +96,7 @@ 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 ]
|
||||
items = [ "Item 0", null, false, 0, null, "Item 1", null, false, 1, null, "Item 2", null, false, 2, null ]
|
||||
selected = 0
|
||||
|
||||
[node name="Quad" type="MeshInstance" parent="."]
|
||||
@@ -16,7 +16,7 @@ _global_script_class_icons={
|
||||
[application]
|
||||
|
||||
config/name="Screen Capture"
|
||||
run/main_scene="res://capture_screen.tscn"
|
||||
run/main_scene="res://screen_capture.tscn"
|
||||
config/icon="res://icon.png"
|
||||
|
||||
[debug]
|
||||
|
||||
@@ -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)
|
||||
# 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")
|
||||
|
||||
# Retrieve the captured image
|
||||
# Retrieve the captured image.
|
||||
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()
|
||||
|
||||
# Create a texture for it
|
||||
# Create a texture for it.
|
||||
var tex = ImageTexture.new()
|
||||
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)
|
||||
|
||||
@@ -3,12 +3,12 @@
|
||||
[ext_resource path="res://screen_capture.gd" type="Script" id=1]
|
||||
[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_bottom = 40.0
|
||||
script = ExtResource( 1 )
|
||||
|
||||
[node name="BG" type="TextureRect" parent="."]
|
||||
[node name="Background" type="TextureRect" parent="."]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
margin_right = 986.0
|
||||
@@ -18,7 +18,7 @@ grow_vertical = 0
|
||||
texture = ExtResource( 2 )
|
||||
expand = true
|
||||
|
||||
[node name="capture" type="TextureRect" parent="."]
|
||||
[node name="CapturedImage" type="TextureRect" parent="."]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
margin_right = 2013.0
|
||||
@@ -29,9 +29,10 @@ rect_scale = Vector2( 0.5, 0.5 )
|
||||
expand = true
|
||||
stretch_mode = 4
|
||||
|
||||
[node name="Button" type="Button" parent="."]
|
||||
[node name="CaptureButton" type="Button" parent="."]
|
||||
margin_left = 48.0
|
||||
margin_top = 53.0
|
||||
margin_right = 188.0
|
||||
margin_bottom = 113.0
|
||||
text = "Capture screen"
|
||||
[connection signal="pressed" from="CaptureButton" to="." method="_on_CaptureButton_pressed"]
|
||||
Reference in New Issue
Block a user