我正在尝试使用and来实现这样的目标,所以我的想法是从这些点获取地标点并部署节点。我使用这个演示作为参考。迄今为止,我已经能够使用. 现在使用这些点将节点添加到场景中。我无法获得深度,这对于节点的位置至关重要。Vision
ARKit
Vision
Vision
ARKit
在搜索 SO 之后,我发现这篇文章要转换CGPoint
为SCNVector3
,但在这里我遇到了一个问题,因为我没有任何参考平面可用于通过命中测试来获得深度。
CGPoint
那么,除了使用s 之外,我如何使用 s 获得完美的深度hitTest
,或者有没有其他方法可以实现视频中显示的结果。
这是实现的代码
CGPoint faceRectCenter = (CGPoint){
CGRectGetMidX(faceRect),CGRectGetMidY(faceRect)
}; // faceRect is detected face bounding box
__block NSMutableArray<ARHitTestResult* >* testResults = [NSMutableArray new];
void(^hitTest)(void) = ^{
NSArray<ARHitTestResult* >* hitTestResults = [self.sceneView hitTest:faceRectCenter types:ARHitTestResultTypeFeaturePoint];
if(hitTestResults.count > 0){
//get the first
ARHitTestResult* firstResult = nil;
for (ARHitTestResult* result in hitTestResults) {
if (result.distance > 0.10) {
firstResult = result;
[testResults addObject:firstResult];
break;
}
}
}
};
for(int i=0; i<3; i++){
hitTest();
}
if(testResults.count > 0){
NSLog(@"%@", testResults);
SCNVector3 postion = averagePostion([testResults copy]);
NSLog(@"<%.1f,%.1f,%.1f>",postion.x,postion.y,postion.z);
__block SCNNode* textNode = [ARTextNode nodeWithText:name Position:postion];
SCNVector3 plane = [self.sceneView projectPoint:textNode.position];
float projectedDepth = plane.z;
NSLog(@"projectedDepth: %f",projectedDepth);
dispatch_async(dispatch_get_main_queue(), ^{
[self.sceneView.scene.rootNode addChildNode:textNode];
[textNode show];
});
}
else{
// NSLog(@"HitTest invalid");
}
}
任何帮助都会很棒!