【发布时间】:2018-06-03 01:16:23
【问题描述】:
图表如下:
ARFrame -> 3DModelFilter(SCNScene + SCNRender) -> OtherFilters -> GPUImageView.
加载 3D 模型:
NSError* error;
SCNScene* scene =[SCNScene sceneWithURL:url options:nil error:&error];
渲染 3D 模型:
SCNRenderer* render = [SCNRenderer rendererWithContext:context options:nil];
render.scene = scene;
[render renderAtTime:0];
现在,我很困惑如何将 ARFrame 的相机变换应用到 SCNScene。
一些猜测:
- 我可以将 ARFrame 相机的变换分配给场景中相机节点的变换而不需要任何复杂的操作吗?
- ARFrame 相机的 projectMatrix 在这种情况下对我没有任何帮助吗?
2017 年 12 月 23 日更新。
首先,感谢@rickster 的回复。根据您的建议,我在 ARSession didUpdateFrame 回调中添加代码:
ARCamera* camera = frame.camera;
SCNMatrix4 cameraMatrix = SCNMatrix4FromMat4(camera.transform);
cameraNode.transform = cameraMatrix;
matrix_float4x4 mat4 = [camera projectionMatrixForOrientation:UIInterfaceOrientationPortrait viewportSize:CGSizeMake(375, 667) zNear:0.001 zFar:1000];
camera.projectionTransform = SCNMatrix4FromMat4(mat4);
运行应用程序。
1.我看不到整艘船,只能看到一部分。所以我在相机的变换中添加了一个翻译。我在下面添加代码,就可以看到整艘船了。
cameraMatrix = SCNMatrix4Mult(cameraMatrix, SCNMatrix4MakeTranslation(0, 0, 15));
2。当我向上或向下移动 iPhone 时,跟踪似乎起作用了。但是当我向左或向右移动 iPhone 时,船会跟随我的移动直到消失在屏幕上。
我认为我错过了一些重要的事情。
【问题讨论】:
-
你有没有得到这个工作/匹配的 ARSCNView?我在做类似的事情,也看到了一些不太正确的结果。谢谢!
标签: ios opengl-es scenekit gpuimage arkit