在visionOS上,Model3D视图的ZStack z-index偏移

huangapple go评论85阅读模式
英文:

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 视图使用相同的 depthalignment 值。

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()
}

huangapple
  • 本文由 发表于 2023年6月29日 18:26:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/76580179.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定