iPad Pro 激光雷达 - 导出几何图形质地 [英] iPad Pro Lidar - Export Geometry & Texture

查看:32
本文介绍了iPad Pro 激光雷达 - 导出几何图形质地的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够从 iPad Pro 激光雷达导出网格和纹理.

I would like to be able to export a mesh and texture from the iPad Pro Lidar.

这里有如何导出网格的示例,但我也希望能够导出环境纹理

There's examples here of how to export a mesh, but Id like to be able to export the environment texture too

ARKit 3.5 –如何使用 LiDAR 从新 iPad Pro 导出 OBJ?

ARMeshGeometry 存储网格的顶点,是否需要在扫描环境时记录"纹理并手动应用它们?

ARMeshGeometry stores the vertices for the mesh, would it be the case that one would have to 'record' the textures as one scans the environment, and manually apply them?

这篇文章似乎展示了一种获取纹理坐标的方法,但我看不到使用 ARMeshGeometry 做到这一点的方法:将 ARFaceGeometry 保存到 OBJ 文件

This post seems to show a way to get texture co-ordinates, but I can't see a way to do that with the ARMeshGeometry: Save ARFaceGeometry to OBJ file

任何方向正确的点,或值得关注的事情,非常感谢!

Any point in the right direction, or things to look at greatly appreciated!

克里斯

推荐答案

您需要计算每个顶点的纹理坐标,将它们应用到网格并提供纹理作为网格的材质.

You need to compute the texture coordinates for each vertex, apply them to the mesh and supply a texture as a material to the mesh.

let geom = meshAnchor.geometry
let vertices = geom.vertices 
let size = arFrame.camera.imageResolution
let camera = arFrame.camera

let modelMatrix = meshAnchor.transform

let textureCoordinates = vertices.map { vertex -> vector_float2 in
    let vertex4 = vector_float4(vertex.x, vertex.y, vertex.z, 1)
    let world_vertex4 = simd_mul(modelMatrix!, vertex4)
    let world_vector3 = simd_float3(x: world_vertex4.x, y: world_vertex4.y, z: world_vertex4.z)
    let pt = camera.projectPoint(world_vector3,
        orientation: .portrait,
        viewportSize: CGSize(
            width: CGFloat(size.height),
            height: CGFloat(size.width)))
    let v = 1.0 - Float(pt.x) / Float(size.height)
    let u = Float(pt.y) / Float(size.width)
    return vector_float2(u, v)
}

// construct your vertices, normals and faces from the source geometry directly and supply the computed texture coords to create new geometry and then apply the texture.

let scnGeometry = SCNGeometry(sources: [verticesSource, textureCoordinates, normalsSource], elements: [facesSource])

let texture = UIImage(pixelBuffer: frame.capturedImage)
let imageMaterial = SCNMaterial()
imageMaterial.isDoubleSided = false
imageMaterial.diffuse.contents = texture
scnGeometry.materials = [imageMaterial]
let pcNode = SCNNode(geometry: scnGeometry)

pcNode 如果添加到您的场景中,将包含应用了纹理的网格.

pcNode if added to your scene will contain the mesh with the texture applied.

来自此处的纹理坐标计算

这篇关于iPad Pro 激光雷达 - 导出几何图形质地的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆