Vuforia 使用 Metal 和 SceneKit
Vuforia using Metal and SceneKit
我在 iOS 上的一个基于 Framemarker 的增强现实应用程序中使用 Vuforia 有一段时间了。我已经厌倦了使用 Kitware 的 VTK,并想切换到 SceneKit。如何使用 Metal 和 Vuforia 最好地绘制场景背景?
我目前的技术 (Objective-C) 涉及从 Vuforia 抓取视频的每一帧:
- (void)Vuforia_onUpdate:(Vuforia::State *)state
{
Vuforia::Frame frame = state->getFrame();
for (int i = 0; i < frame.getNumImages(); i++) {
const Vuforia::Image *image = frame.getImage(i);
if (image->getFormat() == kVuforiaFrameFormat) {
[self.delegate updateCameraSceneWithBitmap:image->getPixels() size:CGSizeMake(image->getWidth(), image->getHeight()) format:OARCameraImageFormatRGB];
}
}
// I also grab out the frame marker poses and convert the matrices to
// SceneKit compatible ones.
}
然后在Swift-land:
// Get image into UIImage and assign to background
scene.background.contents = backgroundImage
这显然涉及不必要地复制图像以及将图像转换为 CGImage
并将其包装在 UIImage
中。目前,使用了大约 50% 的 CPU、高能量影响和闲置了大约 180 MB 的内存。
我还发现 this project 使用旧版本的 Vuforia 和 SceneKit,但它的性能不是很好,它接管了 UIView。我真正想要的是一种在 SCNRenderer
或 SCNView
中添加 Vuforia 相机绘制的方法,从而最大限度地减少 C++ 流血。
如何使用 Metal 将来自 Vuforia 的相机数据绘制到 SCNScene 的背景中,以便我可以在 Objective-C++ 中划分 C++ 代码并通常在 Swift 中工作?
使用UIImage设置场景背景
处理该问题的一种方法是使用我在 VTK 中使用的相同方法。只需将 UIImage 传递到场景的背景内容中。从性能的角度来看不是最优的,但它有效。
func didUpdateCameraImage(image: UIImage?)
{
if let image = image {
_scene?.background.contents = image
}
}
我在 iOS 上的一个基于 Framemarker 的增强现实应用程序中使用 Vuforia 有一段时间了。我已经厌倦了使用 Kitware 的 VTK,并想切换到 SceneKit。如何使用 Metal 和 Vuforia 最好地绘制场景背景?
我目前的技术 (Objective-C) 涉及从 Vuforia 抓取视频的每一帧:
- (void)Vuforia_onUpdate:(Vuforia::State *)state
{
Vuforia::Frame frame = state->getFrame();
for (int i = 0; i < frame.getNumImages(); i++) {
const Vuforia::Image *image = frame.getImage(i);
if (image->getFormat() == kVuforiaFrameFormat) {
[self.delegate updateCameraSceneWithBitmap:image->getPixels() size:CGSizeMake(image->getWidth(), image->getHeight()) format:OARCameraImageFormatRGB];
}
}
// I also grab out the frame marker poses and convert the matrices to
// SceneKit compatible ones.
}
然后在Swift-land:
// Get image into UIImage and assign to background
scene.background.contents = backgroundImage
这显然涉及不必要地复制图像以及将图像转换为 CGImage
并将其包装在 UIImage
中。目前,使用了大约 50% 的 CPU、高能量影响和闲置了大约 180 MB 的内存。
我还发现 this project 使用旧版本的 Vuforia 和 SceneKit,但它的性能不是很好,它接管了 UIView。我真正想要的是一种在 SCNRenderer
或 SCNView
中添加 Vuforia 相机绘制的方法,从而最大限度地减少 C++ 流血。
如何使用 Metal 将来自 Vuforia 的相机数据绘制到 SCNScene 的背景中,以便我可以在 Objective-C++ 中划分 C++ 代码并通常在 Swift 中工作?
使用UIImage设置场景背景
处理该问题的一种方法是使用我在 VTK 中使用的相同方法。只需将 UIImage 传递到场景的背景内容中。从性能的角度来看不是最优的,但它有效。
func didUpdateCameraImage(image: UIImage?)
{
if let image = image {
_scene?.background.contents = image
}
}