Skip to content

armgit / godot

Public Imported from GitHub
0

Godot Engine – Multi-platform 2D and 3D game engine

Fix positioning of the spatial container window relative to the main window.

Fredia Huya-Kouadioe0f617d6f14b
diff --git a/editor/settings/project_settings_editor.cpp b/editor/settings/project_settings_editor.cpp
index e60085caaae..f62b3fd2c97 100644
--- a/editor/settings/project_settings_editor.cpp
+++ b/editor/settings/project_settings_editor.cpp
@@ -357,6 +357,7 @@ void ProjectSettingsEditor::_add_feature_overrides() {
presets.insert("32");
presets.insert("64");
presets.insert("movie");
+ presets.insert("xr_editor");
EditorExport *ee = EditorExport::get_singleton();
diff --git a/platform/android/java/editor/build.gradle b/platform/android/java/editor/build.gradle
index 2940434c6f4..8bbf00e992e 100644
--- a/platform/android/java/editor/build.gradle
+++ b/platform/android/java/editor/build.gradle
@@ -223,7 +223,7 @@ dependencies {
// Android XR dependencies
androidImplementation "org.godotengine:godot-openxr-vendors-androidxr:$versions.openxrVendorsVersion"
- androidImplementation "androidx.xr.scenecore:scenecore:1.0.0-rc01"
+ androidImplementation "androidx.xr.scenecore:scenecore:1.0.0-rc02"
// Meta dependencies
horizonosImplementation "org.godotengine:godot-openxr-vendors-meta:$versions.openxrVendorsVersion"
diff --git a/platform/android/java/editor/src/android/java/org/godotengine/editor/GodotEditor.kt b/platform/android/java/editor/src/android/java/org/godotengine/editor/GodotEditor.kt
index 063f53773a1..08d58d060d8 100644
--- a/platform/android/java/editor/src/android/java/org/godotengine/editor/GodotEditor.kt
+++ b/platform/android/java/editor/src/android/java/org/godotengine/editor/GodotEditor.kt
@@ -62,14 +62,14 @@ open class GodotEditor : BaseGodotEditor() {
companion object {
private val TAG = GodotEditor::class.java.simpleName
+ private val DEFAULT_ACTIVITY_PANEL_PIXEL_DIMENSIONS = IntSize2d(250, 250)
private val MAIN_WINDOW_PANEL_MIN_SIZE = FloatSize3d(0.45f, 0.25f, 0.0f)
- private val SPATIAL_CONTAINER_PANEL_MIN_SIZE = FloatSize3d(0.05f, 0.05f, 0.0f)
}
private val handler = Handler()
private var pendingFullSpaceRequest = false
- private val pendingSpatialContainerLaunches = LinkedList<Intent>()
+ private val pendingSpatialContainerLaunches = LinkedList<Pair<EditorWindowInfo, Intent>>()
private val spatialCapabilitiesChangedListener = Consumer<Set<SpatialCapability>> {
if (canEmbedActivity()) {
@@ -77,8 +77,8 @@ open class GodotEditor : BaseGodotEditor() {
// Launch any queued spatial containers.
Log.v(TAG, "Launching pending spatial container launches..")
- for (pendingLaunch in pendingSpatialContainerLaunches) {
- startSpatialContainerActivity(pendingLaunch)
+ for ((first, second) in pendingSpatialContainerLaunches) {
+ startSpatialContainerActivity(first, second)
}
pendingSpatialContainerLaunches.clear()
} else {
@@ -115,7 +115,7 @@ open class GodotEditor : BaseGodotEditor() {
return scene.spatialCapabilities.contains(SpatialCapability.EMBED_ACTIVITY)
}
- private fun launchSpatialContainerUsingSceneCore(newInstance: Intent, activityOptions: ActivityOptions?): Boolean {
+ private fun launchSpatialContainerUsingSceneCore(editorWindowInfo: EditorWindowInfo, newInstance: Intent, activityOptions: ActivityOptions?): Boolean {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
try {
if (session != null) {
@@ -124,9 +124,9 @@ open class GodotEditor : BaseGodotEditor() {
handler.removeCallbacks(requestHomeSpaceRunnable)
if (canEmbedActivity()) {
Log.v(TAG, "Launching spatial container in FSM")
- startSpatialContainerActivity(newInstance)
+ startSpatialContainerActivity(editorWindowInfo, newInstance)
} else {
- pendingSpatialContainerLaunches.push(newInstance)
+ pendingSpatialContainerLaunches.push(Pair(editorWindowInfo, newInstance))
if (!pendingFullSpaceRequest) {
Log.v(TAG, "Requesting full space")
scene.requestFullSpace()
@@ -149,21 +149,30 @@ open class GodotEditor : BaseGodotEditor() {
}
}
- private fun startSpatialContainerActivity(newInstance: Intent) {
+ private fun startSpatialContainerActivity(editorWindowInfo: EditorWindowInfo, newInstance: Intent) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val scene = session!!.scene
+ val mainPanelWidth = scene.mainPanelEntity.size.width
+ val mainPanelHeight = scene.mainPanelEntity.size.height
+ val spatialContainerBounds = BaseGodotSpatialContainerGame.getSpatialContainerBounds()
+
+ val translationX = if (editorWindowInfo == SPATIAL_CONTAINER_RUN_GAME_INFO_0) {
+ // The first spatial container is positioned to the right of the main panel.
+ mainPanelWidth + spatialContainerBounds.first / 2
+ } else {
+ // The second spatial container is positioned to the left of the main panel.
+ -(mainPanelWidth + spatialContainerBounds.first / 2)
+ }
+ val translationY = -(mainPanelHeight / 2)
+
val activityPanel = ActivityPanelEntity.create(
session!!,
- IntSize2d(500, 500),
+ DEFAULT_ACTIVITY_PANEL_PIXEL_DIMENSIONS,
"Godot Spatial Container Panel for $newInstance",
- Pose(Vector3(0.0f, -scene.mainPanelEntity.size.height, 0.05f), Quaternion.Identity),
+ Pose(Vector3(translationX, translationY, 0.25f), Quaternion.Identity),
scene.activitySpace
)
- activityPanel.addComponent(MovableComponent.createSystemMovable(session!!))
- val spatialContainerPanelResizeComponent = ResizableComponent.create(session!!, SPATIAL_CONTAINER_PANEL_MIN_SIZE) { resizePanelEntity(it) }
- spatialContainerPanelResizeComponent.isFixedAspectRatioEnabled = true
- activityPanel.addComponent(spatialContainerPanelResizeComponent)
// We remove the 'NEW_TASK' flag as launching in a new task prevents embedding.
newInstance.removeFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
@@ -198,7 +207,7 @@ open class GodotEditor : BaseGodotEditor() {
newInstance: Intent,
activityOptions: ActivityOptions?
) {
- if (isSpatialContainerRunGameInfo(editorWindowInfo) && launchSpatialContainerUsingSceneCore(newInstance, activityOptions)) {
+ if (isSpatialContainerRunGameInfo(editorWindowInfo) && launchSpatialContainerUsingSceneCore(editorWindowInfo, newInstance, activityOptions)) {
return
}
super.dispatchNewInstance(editorWindowInfo, newInstance, activityOptions)
diff --git a/platform/android/java/editor/src/main/java/org/godotengine/editor/BaseGodotSpatialContainerGame.kt b/platform/android/java/editor/src/main/java/org/godotengine/editor/BaseGodotSpatialContainerGame.kt
index 96bd8dc231d..797302eef6f 100644
--- a/platform/android/java/editor/src/main/java/org/godotengine/editor/BaseGodotSpatialContainerGame.kt
+++ b/platform/android/java/editor/src/main/java/org/godotengine/editor/BaseGodotSpatialContainerGame.kt
@@ -30,6 +30,7 @@
package org.godotengine.editor
+import android.util.Log
import org.godotengine.godot.GodotLib
/**
@@ -37,7 +38,34 @@ import org.godotengine.godot.GodotLib
*/
abstract class BaseGodotSpatialContainerGame : GodotXRGame() {
companion object {
+ private val TAG = BaseGodotSpatialContainerGame::class.java.simpleName
+
+ private val DEFAULT_SPATIAL_CONTAINER_BOUNDS = Triple(0.5f, 0.5f, 0.5f)
+
@JvmStatic
protected fun isSpatialContainerEnabled() = GodotLib.getGlobal("xr/openxr/extensions/spatial_container/enabled").toBoolean()
+
+ internal fun getSpatialContainerBounds(): Triple<Float, Float, Float> {
+ val spatialContainerBounds = GodotLib.getGlobal("xr/openxr/extensions/spatial_container/bounds")
+ if (!spatialContainerBounds.isNullOrBlank()) {
+ // The returned string has the following format: (x, y, z)
+ val splitComponents = spatialContainerBounds
+ .trim() // remove any leading / trailing whitespaces
+ .trim('(', ')') // remove the leading and trailing parentheses
+ .split(',')
+ if (splitComponents.size == 3) {
+ try {
+ val bounds = Triple(
+ splitComponents[0].toFloat(),
+ splitComponents[1].toFloat(),
+ splitComponents[2].toFloat()
+ )
+ return bounds
+ } catch (_: NumberFormatException) {}
+ }
+ Log.w(TAG, "Error parsing spatial container bounds $spatialContainerBounds")
+ }
+ return DEFAULT_SPATIAL_CONTAINER_BOUNDS
+ }
}
}