英文:
ZStack z-index offset on visionOS with Model3D views
问题
有一种方法可以禁用ZStack对每个连续视图进行Z轴调整,以便它们看起来放置在不同的平面上吗?
英文:
If I take a ZStack and add a bunch of Model3D views to it (to arrange them in 2D space), the ZStack will give each successive view an adjustment to the z-axis, such that they appear to be placed on different planes. Is there a way to disable this?
答案1
得分: 0
要将3D模型放置在相同的Z平面上(假设每个模型的枢轴点位于其中心),请对每个 Model3D 视图使用相同的 depth
和 alignment
值。
import SwiftUI
import RealityKit
import RealityKitContent
struct ContentView: View {
var body: some View {
ZStack {
Model3D(named: "Scene", bundle: realityKitContentBundle)
.frame(depth: 1.0, alignment: .center)
Model3D(named: "Scene", bundle: realityKitContentBundle)
.frame(depth: 1.0, alignment: .center)
}
}
}
#Preview {
ContentView()
}
英文:
To place 3D models on the same Z-plane (in case that the pivot point of each model is in its center), use the same depth
and alignment
values for each Model3D view.
import SwiftUI
import RealityKit
import RealityKitContent
struct ContentView: View {
var body: some View {
ZStack {
Model3D(named: "Scene", bundle: realityKitContentBundle)
.frame(depth: 1.0, alignment: .center)
Model3D(named: "Scene", bundle: realityKitContentBundle)
.frame(depth: 1.0, alignment: .center)
}
}
}
#Preview {
ContentView()
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论