我希望能够从iPad专业激光雷达导出网格和纹理。
这里有如何导出网格的示例,但我也希望能够导出环境纹理
ARKit 3.5 – How to export OBJ from new iPad Pro with LiDAR?
ARMeshGeometry存储网格的顶点,是否需要在扫描环境时“记录”纹理,并手动应用它们?
这篇文章似乎展示了一种获得纹理坐标的方法,但我看不到使用ARMeshGeometry:Save ARFaceGeometry to OBJ file实现这一点的方法
任何方向正确的点,或者值得期待的东西,非常感谢!
克里斯
发布于 2020-05-14 05:44:42
您需要计算每个顶点的纹理坐标,将它们应用于网格,并将纹理作为材质提供给网格。
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计算纹理坐标
https://stackoverflow.com/questions/61538799
复制