Skip to content

Commit 9903b2c

Browse files
committed
Add new example scene_create
- Creates child scene - Has UI panel with Create and Remove buttons - Demonstrates communication into and out of rust
1 parent 144cbcb commit 9903b2c

13 files changed

+285
-125
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ members = [
1111
"bindings_generator",
1212
"examples/hello_world",
1313
"examples/spinning_cube",
14+
"examples/scene_create",
1415
]

examples/scene_create/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
[package]
2-
name = "spinning_cube"
2+
name = "scene_create"
33
version = "0.1.0"
4-
authors = ["karroffel <[email protected]>"]
4+
authors = ["tom.leys <[email protected]>", "karroffel <[email protected]>"]
55

66
[lib]
77
crate-type = ["cdylib"]
88

99
[dependencies]
1010
gdnative = { path = "../../gdnative" }
11+
euclid = "0.19.6"

examples/scene_create/Child.gdns

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[gd_resource type="NativeScript" format=2]
2+
3+
[resource]
4+
resource_name = "Child"
5+
class_name = "Child"
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[gd_scene load_steps=3 format=2]
2+
3+
[ext_resource path="res://Child.gdns" type="Script" id=1]
4+
5+
[sub_resource type="CubeMesh" id=1]
6+
7+
[node name="Child" type="Spatial"]
8+
script = ExtResource( 1 )
9+
10+
[node name="CSGMesh" type="CSGMesh" parent="."]
11+
transform = Transform( 0.9, 0, 0, 0, 0.9, 0, 0, 0, 0.9, 0, 0, 0 )
12+
mesh = SubResource( 1 )
13+
14+
[node name="CSGMesh2" type="CSGMesh" parent="."]
15+
transform = Transform( 0.1, 0, 0, 0, 0.4, 0, 0, 0, 0.1, 0, 2.15568, 0 )
16+
mesh = SubResource( 1 )

examples/scene_create/Main.tscn

Lines changed: 57 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,65 @@
1-
[gd_scene load_steps=5 format=2]
1+
[gd_scene load_steps=4 format=2]
22

3-
[ext_resource path="res://spinning_cube_library.gdnlib" type="GDNativeLibrary" id=1]
3+
[ext_resource path="res://Parent.gdns" type="Script" id=1]
4+
[ext_resource path="res://Panel.gd" type="Script" id=2]
5+
[ext_resource path="res://Child_scene.tscn" type="PackedScene" id=3]
46

5-
[sub_resource type="CubeMesh" id=1]
7+
[node name="Main" type="Spatial"]
68

7-
[sub_resource type="SpatialMaterial" id=2]
8-
roughness = 0.0
9+
[node name="Camera" type="Camera" parent="."]
10+
transform = Transform( 0.707107, 0.5, -0.5, 0, 0.707107, 0.707107, 0.707107, -0.5, 0.5, -9.65923, 12.7955, 9.30623 )
11+
current = true
912

10-
[sub_resource type="NativeScript" id=3]
11-
resource_name = "RustTest"
12-
class_name = "RustTest"
13-
library = ExtResource( 1 )
13+
[node name="Parent" type="Spatial" parent="."]
14+
script = ExtResource( 1 )
1415

15-
[node name="Main" type="Spatial"]
16+
[node name="Ui" type="Node2D" parent="."]
1617

17-
[node name="Cube" type="MeshInstance" parent="."]
18-
mesh = SubResource( 1 )
19-
material/0 = SubResource( 2 )
20-
script = SubResource( 3 )
21-
base/rotate_speed = 1.0
22-
test/test_enum = null
23-
test/test_flags = null
18+
[node name="Canvas" type="CanvasLayer" parent="Ui"]
2419

25-
[node name="Camera" type="Camera" parent="."]
26-
transform = Transform( 0.572229, -0.327396, 0.751909, 0, 0.916856, 0.399217, -0.820094, -0.228443, 0.524651, 4.71648, 2.5, 3.45846 )
27-
current = true
20+
[node name="Panel" type="Panel" parent="Ui/Canvas"]
21+
margin_top = 533.0
22+
margin_right = 1023.0
23+
margin_bottom = 598.0
24+
grow_horizontal = 2
25+
grow_vertical = 2
26+
script = ExtResource( 2 )
27+
28+
[node name="Add" type="Button" parent="Ui/Canvas/Panel"]
29+
margin_left = 28.8019
30+
margin_top = 18.0811
31+
margin_right = 160.802
32+
margin_bottom = 48.0811
33+
text = "Add Child"
34+
35+
[node name="Remove" type="Button" parent="Ui/Canvas/Panel"]
36+
margin_left = 179.803
37+
margin_top = 19.4414
38+
margin_right = 311.803
39+
margin_bottom = 49.4414
40+
text = "Remove Child"
41+
42+
[node name="Label" type="Label" parent="Ui/Canvas/Panel"]
43+
margin_left = 345.0
44+
margin_top = 21.0
45+
margin_right = 580.0
46+
margin_bottom = 40.0
47+
text = "No Children have been created yet"
48+
49+
[node name="Child" parent="." instance=ExtResource( 3 )]
50+
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -5, 0, -5 )
51+
visible = false
52+
53+
[node name="Child2" parent="." instance=ExtResource( 3 )]
54+
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 5, 0, 5 )
55+
visible = false
56+
57+
[node name="Child3" parent="." instance=ExtResource( 3 )]
58+
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -5.21943, 0, 5 )
59+
visible = false
2860

61+
[node name="Child4" parent="." instance=ExtResource( 3 )]
62+
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 4.30119, 0, -4.46641 )
63+
visible = false
64+
[connection signal="pressed" from="Ui/Canvas/Panel/Add" to="Ui/Canvas/Panel" method="_on_Add_pressed"]
65+
[connection signal="pressed" from="Ui/Canvas/Panel/Remove" to="Ui/Canvas/Panel" method="_on_Remove_pressed"]

examples/scene_create/Panel.gd

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
extends Panel
2+
3+
func _ready():
4+
pass # Replace with function body.
5+
6+
# There is a signal set up on the Add button which calls
7+
# this method. We pass the call into Parent.spawn_1
8+
# (This calls Rust)
9+
func _on_Add_pressed():
10+
var spawner_node = get_node("/root/Main/Parent")
11+
spawner_node.spawn_1("example string")
12+
13+
# There is a signal set up on the Remove button which calls
14+
# this method. We pass the call into Parent.remove_1
15+
# (This calls Rust)
16+
func _on_Remove_pressed():
17+
var spawner_node = get_node("/root/Main/Parent")
18+
spawner_node.remove_1("Another example string")
19+
20+
# This function is called from Rust. All we need there is this
21+
# node and the name "set_num_children"
22+
func set_num_children(children_count):
23+
# This is called from rust
24+
if children_count == 0 :
25+
$Label.text = "What did you go and kill all the children for!?"
26+
elif children_count == 1:
27+
$Label.text = "We have one child"
28+
else :
29+
$Label.text = "%d children have been created so far" % children_count
30+
31+
32+

examples/scene_create/Parent.gdns

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[gd_resource type="NativeScript" load_steps=2 format=2]
2+
3+
[ext_resource path="res://scene_create_library.gdnlib" type="GDNativeLibrary" id=1]
4+
5+
[resource]
6+
resource_name = "ChildSpawner"
7+
class_name = "SceneCreate"
8+
library = ExtResource( 1 )

examples/scene_create/default_env.tres

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,3 @@ sun_energy = 16.0
1212
[resource]
1313
background_mode = 2
1414
background_sky = SubResource( 1 )
15-

examples/scene_create/project.godot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ _global_script_class_icons={
1515

1616
[application]
1717

18-
config/name="Godot Rust - Misc Mesh Playground"
18+
config/name="Godot Rust - Scene Create Example"
1919
run/main_scene="res://Main.tscn"
2020
config/icon="res://icon.png"
2121

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[general]
2+
3+
singleton=false
4+
load_once=false
5+
symbol_prefix="godot_"
6+
reloadable=true
7+
8+
[entry]
9+
10+
OSX.64="../../target/debug/libscene_create.dylib"
11+
X11.64="../../target/debug/libscene_create.so"
12+
Windows.64="res://../../target/debug/scene_create.dll"
13+
14+
[dependencies]
15+
16+
OSX.64=[ ]
17+
UWP.64=[ ]
18+
X11.64=[ ]

examples/scene_create/spinning_cube_library.gdnlib

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)