【问题标题】:iPad Pro Lidar - Export Geometry & TextureiPad Pro Lidar - 导出几何和纹理
【发布时间】:2020-08-15 17:24:43
【问题描述】:

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

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

ARKit 3.5 – How to export OBJ from new iPad Pro with LiDAR?

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

这篇文章似乎展示了一种获取纹理坐标的方法,但我看不到使用 ARMeshGeometry 的方法:Save ARFaceGeometry to OBJ file

任何正确方向的观点,或值得一看的东西都非常感谢!

克里斯

【问题讨论】:

    标签: arkit lidar


    【解决方案1】:

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

    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 将包含应用了纹理的网格。

    来自here的纹理坐标计算

    【讨论】:

    • 您能否在从网格生成 .obj 文件的同时添加更多示例?也许一个示例项目会很有用
    • 有没有机会分享一个更完整的实现,@Pavan K?这看起来很有希望,但我有点不确定像 verticesSourcenormalsSourcefacesSource 这样的东西来自哪里。
    • @ZbadhabitZ 你不需要将 CVPixelBuffer 转换为 UImage .. 这是一个昂贵的操作,上面的代码只是一个例子。 imageMaterial.diffuse.contents 采用 MTLTexture .. 如果需要,您可以将 CVPixelBuffer 转换为实时工作的纹理
    • 此代码适用于单个帧,但是如何将其余的相机图像拼接到其他网格?
    • 这不起作用
    【解决方案2】:

    通过here查看我的回答

    这是对这个项目的描述:MetalWorldTextureScan,它演示了如何使用 ARKit 和 Metal 扫描您的环境并创建纹理网格。

    【讨论】:

      猜你喜欢
      • 2020-07-18
      • 2012-11-25
      • 2021-05-02
      • 2020-12-26
      • 1970-01-01
      • 2023-01-07
      • 1970-01-01
      • 1970-01-01
      • 2011-10-13
      相关资源
      最近更新 更多