iPad Pro Lidar-导出几何和质地 [英] iPad Pro Lidar - Export Geometry & Texture

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

问题描述

我希望能够从iPad Pro Lidar导出网格和纹理.

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进行纹理坐标的方法:

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 Lidar-导出几何和质地的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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