RealityKit–使用`.rcproject` vs` .usdz'加载模型之间的区别
我正在构建一个简单的应用程序,该应用在用户脸上添加了帽子。我已经看到了两种不同方法的示例:
- 将对象作为场景添加到
experience.rcproject
- 直接从捆绑包中读取对象的
.usdz
file> file
方法#1
struct ARViewContainer: UIViewRepresentable {
func makeUIView(context: Context) -> ARView {
arView = ARView(frame: .zero)
arView.automaticallyConfigureSession = false
return arView
}
func updateUIView(_ uiView: ARView, context: Context) {
let arConfiguration = ARFaceTrackingConfiguration()
uiView.session.run(arConfiguration,
options:[.resetTracking, .removeExistingAnchors])
let arAnchor = try! Experience.loadHat()
uiView.scene.anchors.append(arAnchor)
}
}
方法#2
struct ARViewContainer: UIViewRepresentable {
func makeUIView(context: Context) -> ARView {
let arView = ARView(frame: .zero)
let modelEntity = try! ModelEntity.load(named: "hat.usdz")
modelEntity.position = SIMD3(0, 0, -8)
modelEntity.orientation = simd_quatf.init(angle: 0, axis: SIMD3(-90, 0, 0))
modelEntity.scale = SIMD3(0.02, 0.02, 0.02)
arView.session.run(ARFaceTrackingConfiguration())
let anchor = AnchorEntity(.face)
anchor.position.y += 0.25
anchor.addChild(modelEntity)
arView.scene.addAnchor(anchor)
return arView
}
func updateUIView(_ uiView: ARView, context: Context) {
let arConfiguration = ARFaceTrackingConfiguration()
uiView.session.run(arConfiguration,
options:[.resetTracking, .removeExistingAnchors])
let fileName = "hat.usdz"
let modelEntity = try! ModelEntity.loadModel(named: fileName)
modelEntity.position = SIMD3(0, 0, -8)
modelEntity.orientation = simd_quatf.init(angle: 0, axis: SIMD3(-90, 0, 0))
modelEntity.scale = SIMD3(0.02, 0.02, 0.02)
let arAnchor = AnchorEntity(.face)
arAnchor.addChild(modelEntity)
uiView.scene.anchors.append(arAnchor)
}
}
这些方法之间的主要区别是什么?方法1有效,但问题是方法#2甚至对我不起作用 - 该对象根本不会加载到场景中。谁能解释一下?
谢谢!
I'm building a simple app that adds a hat on top of the user's face. I've seen examples of 2 different approaches:
- Adding the object as a scene to
Experience.rcproject
- Reading the object from the bundle directly as a
.usdz
file
Approach #1
struct ARViewContainer: UIViewRepresentable {
func makeUIView(context: Context) -> ARView {
arView = ARView(frame: .zero)
arView.automaticallyConfigureSession = false
return arView
}
func updateUIView(_ uiView: ARView, context: Context) {
let arConfiguration = ARFaceTrackingConfiguration()
uiView.session.run(arConfiguration,
options:[.resetTracking, .removeExistingAnchors])
let arAnchor = try! Experience.loadHat()
uiView.scene.anchors.append(arAnchor)
}
}
Approach #2
struct ARViewContainer: UIViewRepresentable {
func makeUIView(context: Context) -> ARView {
let arView = ARView(frame: .zero)
let modelEntity = try! ModelEntity.load(named: "hat.usdz")
modelEntity.position = SIMD3(0, 0, -8)
modelEntity.orientation = simd_quatf.init(angle: 0, axis: SIMD3(-90, 0, 0))
modelEntity.scale = SIMD3(0.02, 0.02, 0.02)
arView.session.run(ARFaceTrackingConfiguration())
let anchor = AnchorEntity(.face)
anchor.position.y += 0.25
anchor.addChild(modelEntity)
arView.scene.addAnchor(anchor)
return arView
}
func updateUIView(_ uiView: ARView, context: Context) {
let arConfiguration = ARFaceTrackingConfiguration()
uiView.session.run(arConfiguration,
options:[.resetTracking, .removeExistingAnchors])
let fileName = "hat.usdz"
let modelEntity = try! ModelEntity.loadModel(named: fileName)
modelEntity.position = SIMD3(0, 0, -8)
modelEntity.orientation = simd_quatf.init(angle: 0, axis: SIMD3(-90, 0, 0))
modelEntity.scale = SIMD3(0.02, 0.02, 0.02)
let arAnchor = AnchorEntity(.face)
arAnchor.addChild(modelEntity)
uiView.scene.anchors.append(arAnchor)
}
}
What is the main difference between these approaches? Approach #1 works, but the issue is that approach #2 doesn't even work for me - the object simply doesn't load into the scene. Could anyone explain a bit?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
.rcproject
和.usdz
之间的差异很明显:现实作曲家文件已经具有模型的锚点(并且它位于层次结构的顶部)。当您在现实作曲家中原型原型时,您可以在视觉上控制模型的规模。.usdz
模型通常具有巨大的规模,您需要减少100次。通常,
.usdz
模型没有地板,而.rcproject
默认情况下具有地板,并且该地板充当阴影捕捉器。另外,请注意,.rcproject
文件大于.usdz
文件。将pythonaly )。使用
.usdz
加载到场景中时,您必须以编程方式创建一个锚点(.reality
文件,因为它们被优化以用于更快的加载,也很有意义。另外,在
makeuiview
方法中放置面部跟踪配置:另外,检查以下渲染选项是否已禁用。
并检查帽子模型中枢轴点的位置。
The difference between
.rcproject
and.usdz
is quite obvious: the Reality Composer file already has an anchor for the model (and it's at the top of the hierarchy). When you prototype in Reality Composer, you have the ability to visually control the scale of your models..usdz
models very often have a huge scale, which you need to reduce by 100 times.As a rule,
.usdz
model doesn't have a floor, while.rcproject
has a floor by default and this floor acts as a shadow catcher. Also, note that the.rcproject
file is larger than the.usdz
file.When loading
.usdz
into a scene, you have to programmatically create an anchor (either swiftly or pythonically). It also makes sense to use.reality
files as they are optimized for faster loading.Also, put a face tracking config inside
makeUIView
method:Also, check if the following render options are disabled.
And check a position of pivot point in hat model.
对于2号方法,请尝试删除模型性的位置。您提供的位置为0,-4.9和11.8。这些位置为米。因此,尝试将其删除,看看是否出现。
For approach number 2, try removing the the position for the modelEntity. You provided position as 0, -4.9 and 11.8. Those positions are in meters. So try to remove it and see if appears.