-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
More example scenes; better scene switching UI.
- Loading branch information
Showing
51 changed files
with
1,780 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// Created by Kevin Watters on 12/27/23. | ||
|
||
import SwiftUI | ||
import RealityKit | ||
import GodotVision | ||
|
||
/// The path to the folder containing the "project.godot" you wish Godot to load. | ||
fileprivate let pathToGodotProject = "Godot_Project" | ||
|
||
fileprivate let exampleScenes: [(label: String, systemImageName: String, resourcePath: String)] = [ | ||
("Hello", "hand.wave", "res://examples/hello/example_godot_vision_scene.tscn"), | ||
("Physics", "shippingbox.and.arrow.backward", "res://examples/physics_toy/physics_toy.tscn"), | ||
("Skeletons", "figure.cooldown", "res://examples/rigged_models/example_rigged_models.tscn"), | ||
("Joints", "lamp.desk.fill", "res://scenes/joints/joints.tscn"), | ||
//("Soft Bodies", resourcePath: "res://scenes/soft_bodies/soft_bodies.tscn"), | ||
("CSG", "circle.circle", "res://examples/csg/csg.tscn"), | ||
] | ||
|
||
fileprivate let UI_PANEL_ATTACHMENT_NAME = "ui_panel" | ||
|
||
|
||
struct ExampleScenesBrowser: View { | ||
@StateObject private var godotVision = GodotVisionCoordinator() | ||
@State private var selectedScene: String = exampleScenes[0].resourcePath | ||
@State private var showSettings: Bool = false | ||
|
||
var body: some View { | ||
GeometryReader3D { (geometry: GeometryProxy3D) in | ||
RealityView { content, attachments in | ||
// Initialize Godot | ||
let rkEntityGodotRoot = godotVision.setupRealityKitScene(content, volumeSize: VOLUME_SIZE, projectFileDir: pathToGodotProject) | ||
print("Godot scene root: \(rkEntityGodotRoot)") | ||
|
||
if let uiPanel = attachments.entity(for: UI_PANEL_ATTACHMENT_NAME) { | ||
content.add(uiPanel) | ||
uiPanel.position = uiPanelPosition(volumeSize: VOLUME_SIZE) | ||
} | ||
} update: { content, attachments in | ||
// update called when SwiftUI @State in this ContentView changes. See docs for RealityView. | ||
// user can change the volume size from the default by selecting a different zoom level. | ||
// we watch for changes via the GeometryReader and scale the godot root accordingly | ||
let frame = content.convert(geometry.frame(in: .local), from: .local, to: .scene) | ||
let volumeSize = simd_double3(frame.max - frame.min) | ||
godotVision.changeScaleIfVolumeSizeChanged(volumeSize) | ||
if let uiPanel = attachments.entity(for: UI_PANEL_ATTACHMENT_NAME) { | ||
// swiftui attachment also needs to be repositioned | ||
uiPanel.position = uiPanelPosition(volumeSize: volumeSize) | ||
} | ||
} attachments: { | ||
Attachment(id: "ui_panel") { | ||
HStack { | ||
Button { godotVision.reloadScene() } label: { | ||
Label("Reload", systemImage: "arrow.clockwise.circle") | ||
} | ||
Button { withAnimation { showSettings.toggle() } } label: { | ||
Label("Settings", systemImage: "gear") | ||
} | ||
if showSettings { | ||
GodotVisionSettingsView(godotVision: godotVision) | ||
} | ||
}.padding().glassBackgroundEffect() | ||
} | ||
} | ||
} | ||
.modifier(GodotVisionRealityViewModifier(coordinator: godotVision)) | ||
.onChange(of: selectedScene) { _, sceneResourcePath in | ||
godotVision.changeSceneToFile(atResourcePath: sceneResourcePath) | ||
} | ||
.ornament(visibility: .automatic, attachmentAnchor: .scene(.leading), contentAlignment: .center) { | ||
// Show a tab bar on the left allowing the user to select example scenes. | ||
TabView(selection: $selectedScene) { | ||
ForEach(exampleScenes, id: \.resourcePath) { (label, systemImage, resourcePath) in | ||
Tab(label, systemImage: systemImage, value: resourcePath) { /* empty tab content; we load the scene in .onChange(of: selectedScene) */ } | ||
} | ||
} | ||
} | ||
} | ||
|
||
private func uiPanelPosition(volumeSize: simd_double3) -> simd_float3 { | ||
.init(0, Float(volumeSize.y / -2 + 0.1), Float(volumeSize.z / 2 - 0.01)) | ||
} | ||
} | ||
|
||
#Preview(windowStyle: .volumetric) { | ||
ExampleScenesBrowser() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Created by Kevin Watters on 10/8/24. | ||
|
||
import SwiftUI | ||
import GodotVision | ||
|
||
struct GodotVisionSettingsView: View { | ||
@ObservedObject var godotVision: GodotVisionCoordinator | ||
|
||
var body: some View { | ||
Text("Physics FPS") | ||
Picker("Physics FPS", selection: $godotVision.physicsTicksPerSecond) { | ||
Text("30").tag(30) | ||
Text("60").tag(60) | ||
Text("90").tag(90) | ||
}.frame(width: 150).pickerStyle(.palette) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[gd_resource type="Environment" load_steps=3 format=3 uid="uid://cgl5t5rlv6o6v"] | ||
|
||
[sub_resource type="PhysicalSkyMaterial" id="PhysicalSkyMaterial_yivqe"] | ||
rayleigh_color = Color(0.301961, 0.403922, 0.6, 1) | ||
mie_color = Color(0.690196, 0.729412, 0.811765, 1) | ||
ground_color = Color(0.690196, 0.729412, 0.811765, 1) | ||
|
||
[sub_resource type="Sky" id="Sky_tuy8d"] | ||
sky_material = SubResource("PhysicalSkyMaterial_yivqe") | ||
|
||
[resource] | ||
background_mode = 2 | ||
sky = SubResource("Sky_tuy8d") | ||
tonemap_mode = 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[gd_resource type="StandardMaterial3D" format=3 uid="uid://3dvxsth5fn3n"] | ||
|
||
[resource] | ||
cull_mode = 2 | ||
shading_mode = 2 | ||
specular_mode = 2 | ||
albedo_color = Color(0.294118, 0.270588, 0.227451, 1) | ||
metallic_specular = 0.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[gd_resource type="StandardMaterial3D" format=3 uid="uid://ctm5wb05otmn4"] | ||
|
||
[resource] | ||
cull_mode = 2 | ||
shading_mode = 2 | ||
specular_mode = 2 | ||
albedo_color = Color(0.435294, 0.643137, 0, 1) | ||
metallic_specular = 0.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[gd_resource type="StandardMaterial3D" format=3 uid="uid://bd8s48i3httg2"] | ||
|
||
[resource] | ||
cull_mode = 2 | ||
shading_mode = 2 | ||
specular_mode = 2 | ||
albedo_color = Color(0.2, 0.2, 0.2, 1) | ||
metallic_specular = 0.0 |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.