Zba*_*itZ 5 augmented-reality arkit arbodyanchor
我一直在努力学习如何使用 Apple 的示例项目执行 3D 身体跟踪。我的目标是用我自己的 3D 模型替换这个项目中的模型,我已经构建了该模型以匹配该项目中包含的 Apple 可用的“robot.usdz”示例。
在转换为 USDZ 后,我已经成功地将我的 3D 模型导入到 Xcode 中,并将模型附加到 ARBodyAnchor。然而,我的模型(见附件截图)出现在预期的位置,但看起来完全错误。我正在加载模型;
var cancellable: AnyCancellable? = nil
cancellable = Entity.loadBodyTrackedAsync(named: "character/mytest").sink(
receiveCompletion: { completion in
if case let .failure(error) = completion {
print("Error: Unable to load model: \(error.localizedDescription)")
}
cancellable?.cancel()
}, receiveValue: { (character: Entity) in
if let character = character as? BodyTrackedEntity {
character.scale = [0.5, 0.5, 0.5]
self.character = character
cancellable?.cancel()
} else {
print("Error: Unable to load model as BodyTrackedEntity")
}
})
Run Code Online (Sandbox Code Playgroud)
当我简单地将这个相同的模型作为一个实体导入时,去掉身体跟踪,我可以将它附加到水平面或身体上,并且它正常加载。因此,出于 3D 跟踪的目的,模型出现了问题。
有没有人成功地将自定义 3D 模型加载到 Xcode 中以用于身体跟踪?
robot.usdz要在实时 ARKit/RealityKit 动捕中使用自定义角色模型(而不是 Apple 的),请完成以下步骤(并仔细阅读为 MoCap 绑定模型文章):
这是代码:
import SwiftUI
import RealityKit
import ARKit
struct ContentView : View {
var body: some View {
ARContainer().ignoresSafeArea()
}
}
Run Code Online (Sandbox Code Playgroud)
struct ARContainer : UIViewRepresentable {
var arView = ARView(frame: .zero)
func makeUIView(context: Context) -> ARView {
arView.automaticallyConfigureSession = false
let config = ARBodyTrackingConfiguration()
arView.session.run(config, options: .resetTracking)
do {
let body = try Entity.loadBodyTracked(named: "Custom_Model")
let material_00 = SimpleMaterial(color: .white, isMetallic: true)
let material_01 = OcclusionMaterial()
body.model?.materials = [material_00, material_01]
let anchor = AnchorEntity(.body)
body.setParent(anchor)
arView.scene.anchors.append(anchor)
} catch {
print("Can't load Body Tracked Entity...")
}
return arView
}
func updateUIView(_ view: ARView, context: Context) { }
}
Run Code Online (Sandbox Code Playgroud)
USDZ 模型有两个着色器:OcclusionMaterial用于身体和SimpleMaterial衣领:
唯一的问题是,即使视觉系统清楚地区分被跟踪的现实世界身体,ARKit/RealityKit 的实时 MoCap 也非常不稳定(模型经常无法控制地晃动)。
| 归档时间: |
|
| 查看次数: |
512 次 |
| 最近记录: |