【发布时间】:2019-10-08 07:36:31
【问题描述】:
我有这本书,但我目前正在从 AR/VR 周免费的视频教程中重新混合家具应用程序。
我想要一个与检测到的墙壁/垂直平面对齐的 3D 墙壁画布。
事实证明这比我想象的要难。定位不是问题。就像家具放置应用程序一样,您只需获取 hittest.worldtransform 的 column3 并为此 vector3 提供位置的新几何。
但我不知道我必须做什么才能让我的 3D 对象旋转到在对齐的检测平面上面向前方。因为我有一个画布对象,所以照片位于画布的一侧。放置时,照片总是背对着。
我曾考虑对画布进行任意旋转以使其面向前方,但只有当我向北看并将画布放在我右侧的墙上时,这才是正确的。
我在网上尝试了很多解决方案,但一个总是使用 .existingPlaneUsingExtent。用于垂直平面检测。这允许您从
hittest.anchor? as ARPlaneAnchor。
如果您在使用.estimatedVerticalPlane 时尝试这个anchor?是nil
我也没有继续沿着这条路线走下去,因为我的水平 3D 对象开始被放置在空中。这可能归结为控制流逻辑,但在垂直画布放置正常工作之前我会忽略它。
我目前的思路是获取画布的正面矢量,并将其旋转到检测到的垂直平面的正面矢量UIImage 或命中点。
如何从 3D 点获得前向矢量。或者从网格图像中获取正面矢量,即UIImage,当ARKit 检测到垂直墙时作为叠加层放置?
这是一个例子。画布显示画布的背面,并且与作为列的检测到的垂直平面不平行。但是有一个“在此处放置海报”网格,我希望画布与之对齐,并且我可以看到照片。
我尝试过的事情。
使用.estimatedVerticalPlane
ARKit estimatedVerticalPlane hit test get plane rotation
我不知道如何正确应用这个矩阵和来自 SO 答案的 eular 角度结果。
我的添加图片功能。
func addPicture(hitTestResult: ARHitTestResult) {
// I would like to convert estimate hitTest to a anchorpoint
// it is easier to rotate a node to a anchorpoint over calculating eularAngles
// we have all detected anchors in the _Renderer SCNNode. however there are
// Get the current furniture item, correct its position if necessary,
// and add it to the scene.
let picture = pictureSettings.currentPicturePiece()
//look for the vertical node geometry in verticalAnchors
if let hitPlaneAnchor = hitTestResult.anchor as? ARPlaneAnchor {
if let anchoredNode = verticalAnchors[hitPlaneAnchor]{
//code removed as a .estimatedVerticalPlane hittestResult doesn't get here
}
}else{
// Transform hitresult to world coords
let worldTransform = hitTestResult.worldTransform
let anchoredNodeOrientation = worldTransform.eulerAngles
picture.rotation.y =
-.pi * anchoredNodeOrientation.y
//set the transform matirs
let positionMatris = worldTransform.columns.3
let position = SCNVector3 (
positionMatris.x,
positionMatris.y,
positionMatris.z
)
picture.position = position + pictureSettings.currentPictureOffset();
}
//parented to rootNode of the scene
sceneView.scene.rootNode.addChildNode(picture)
}
感谢您提供的任何帮助。
编辑: 我注意到“手性”或 3D 模型不正确/相反? 正 Z 指向左侧,正 X 面向相机,因为我期望的是模型的正面。这是个问题吗?
【问题讨论】: