我正在尝试了解和使用ARKit。但是有一件事我无法完全理解。
苹果关于ARAnchor说:
现实世界中的位置和方向,可用于在AR场景中放置对象。
但这还不够。所以我的问题是:
ARAnchor什么? ARAnchor的特征点只是一部分? 该ARFaceTrackingConfigurationARKit场所ARFaceAnchor有关的位置和面部的朝向到现场信息。除其他外,此锚具有lookAtPoint我感兴趣的属性。我知道此向量相对于面部。如何在屏幕上为此位置绘制一个点,这意味着如何转换该点的坐标?
RealityKit 的文档包括 structs: OcclusionMaterial, SimpleMaterial, 和UnlitMaterial用于将材料添加到ModelEntity.
或者,您可以加载一个带有材料的模型。
我想以ModelEntity编程方式向 a 添加自定义材料/纹理。如何在不将材质添加到 Reality Composer 或其他一些 3D 软件中的模型的情况下即时实现这一点?
我正在尝试将平面检测添加到一个简单的ARKit应用中。我想将图片放在垂直平面上。
因此,首先我需要检测平面,然后可以添加在RealityKit中创建的对象锚。
但是问题是我不确定使用ARKit 3和Xcode 11检测平面并将其添加到场景中的正确方法。
它应该很简单:
import ARKit
import RealityKit
@IBOutlet var arView: ARView!
override func viewDidLoad() {
super.viewDidLoad()
let arConfiguration = ARWorldTrackingConfiguration()
arConfiguration.planeDetection = .horizontal
arView.session.run(arConfiguration)
}
Run Code Online (Sandbox Code Playgroud)
但是我收到以下错误:
类型“ ARView”的值没有成员“会话”
我什至尝试了以下内容,Apple在其WWDC演示(4:27)中将其用作示例,
苹果演示!
let anchor = AnchorEntity(plane: .verticle, minimumBounds: [0.2, 0.2])
arView.scene.addAnchor(anchor)
Run Code Online (Sandbox Code Playgroud)
但是尝试创建AnchorEntity时出现以下错误
表达式类型“ AnchorEntity”在没有更多上下文的情况下是模棱两可的
import UIKit
import RealityKit
import ARKit
class ViewController: UIViewController {
@IBOutlet var arView: ARView!
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
// Create a session configuration
}
override func viewDidLoad() {
super.viewDidLoad()
}
func …Run Code Online (Sandbox Code Playgroud) 我想知道是否可以将worldMap二进制数据(存储空间映射状态和一组 ARAnchors)转换为json或xml文件?
func writeWorldMap(_ worldMap: ARWorldMap, to url: URL) throws {
let data = try NSKeyedArchiver.archivedData(withRootObject: worldMap,
requiringSecureCoding: true)
try data.write(to: url)
}
Run Code Online (Sandbox Code Playgroud)
如果可能,我可以使用哪些工具?
纹理是否可以具有 alpha 透明度?
我有包含 8 位 RGBA 的 png 文件,但由于某种原因,应该透明的部分只是黑色。
我这样分配材料:
private func setupLightMeshes(_ scene: Entity) {
let lightEntity = scene.findEntity(named: "LightWindow_Plane")!
var lightMaterial = UnlitMaterial()
lightMaterial.baseColor = try! MaterialColorParameter.texture(
TextureResource.load(named: "light.png")) // this is 8bpc RGBA
var modelComponent = lightEntity.components[ModelComponent] as! ModelComponent
modelComponent = ModelComponent(mesh: modelComponent.mesh, materials: [lightMaterial])
lightEntity.components.set(modelComponent)
}
Run Code Online (Sandbox Code Playgroud) 我试图理解有关 Scenekit 的 Apple 文档,在谈论 SCNNode 变量时发现一些问题:
\n例如,使用 simdScale 变量或scale 变量应用比例有什么区别?
\n阅读文档,\n无法理解何时以及为何使用“管理节点\xe2\x80\x99s 变换(SceneKit 类型)”下的变量以及何时使用管理节点变换下的变量
\n例如,使用 var "scale" 还是 simdScale 更改 SCNode 的比例更好?
\n我正在使用 RealityKit 并努力设置应该可读并放置在盒子上的文本。无论盒子如何设置,它都应该始终遵循盒子的位置。
let textMesh = MeshResource.generateText("ABC", extrusionDepth: 0.001, font: fonts)
let textEntity = ModelEntity(mesh: textMesh, materials: [UnlitMaterial(color: .black)])
let boxMeshForText = MeshResource.generateBox(width: 0.25,
height: 0.1,
depth: 0,
cornerRadius: 0.001)
let boxEntityForText = ModelEntity(mesh: boxMeshForText,
materials: [UnlitMaterial(color: UIColor.white)])
textEntity.setPosition([-0.09, -0.03, 0.001], relativeTo: boxEntityForText)
boxEntityForText.addChild(textEntity)
let textAnchor = ARAnchorEntity()
textAnchor.addChild(boxEntityForText, preservingWorldTransform: true)
textAnchor.setPosition([0.05, 0.05, 0.02], relativeTo: anchor)
textAnchor.transform.rotation = simd_quatf(angle: -90 * .pi/180, axis: [1,0,0])
anchor.addChild(textAnchor)
Run Code Online (Sandbox Code Playgroud)
上面的代码给了我错误的结果。我想要的结果可以在附图中看到。
在 Unity 中,我们可以使用环境深度来实现遮挡。它在幕后使用 ARKit。我如何在 iOS ARkit 中实现相同的行为。
我知道我们可以用深度配置帧语义,但我怀疑它真的与统一环境深度遮挡相同吗?
// Build the set of required frame semantics.
let semantics: ARConfiguration.FrameSemantics = [.sceneDepth]
configuration.frameSemantics = semantics
session.run(configuration)
Run Code Online (Sandbox Code Playgroud) 我认为 RealityView 应该能够做更多奇特的事情,但我仍然想弄清楚它们之间的确切区别。目前,它们彼此太相似了,例如它们都需要一个实体名称来初始化。我想知道什么时候 Model3D 就足够了,什么时候必须使用 RealityView?