我试着在检测到的图像上放置一个3D对象,并且成功了。但当我在图像周围移动相机时,对象并没有停留在图像的中心。有没有办法在图像的中心添加一个常规的锚点来帮助我将3D对象固定在正确的位置?下面的代码是我尝试过的,但它不起作用。
- (void)renderer:(id<SCNSceneRenderer>)renderer didAddNode:(SCNNode *)node forAnchor:(ARAnchor *)anchor
{
if ([anchor isKindOfClass:[ARImageAnchor class]]) {
ARAnchor *newAnchor = [[ARAnchor alloc] initWithTransform:anchor.transform];
[self.sceneView.session addAnchor:newAnchor];
}
}I detect an image and put a plane on it, it looks center correctly
But when I move the camera to another position, it doesn't locate on the center of image
发布于 2019-05-22 17:25:32
不需要创建新的锚点,因为ARKit已经提供了一个锚点。您应该将3D内容添加到此方法提供的节点中。根据renderer:didAddNode:forAnchor:文档:
通过将几何体(或其他SceneKit特征)附加到此节点或添加子节点,可以为锚点提供可视内容。
因此,在此方法中:
- (void)renderer:(id<SCNSceneRenderer>)renderer didAddNode:(SCNNode *)node forAnchor:(ARAnchor *)anchor
{
[node addChildNode: your3DObjectNode];
}然后它应该停留在你的图像的中心。
https://stackoverflow.com/questions/56248793
复制相似问题