= meshAnchor.geometry.vertices let faces = meshAnchor.geometry.faces let size = camera.imageResolution let vertexSource = SCNGeometrySource(buffer: vertices.buffer, vertexFormat: vertices.format, semantic: .vertex, vertexCount: vertices.count, dataOffset: vertices.offset, dataStride: vertices.stride) let modelMatrix = meshAnchor.transform var textCords = [CGPoint]() for index in 0..<vertices.count { let vertexPointer = vertices.buffer.contents().advanced(by: vertices.offset + vertices.stride * index) let vertex = vertexPointer.assumingMemoryBound(to: (Float, Float, Float).self).pointee let vertex4 = SIMD4<Float>(vertex.0, vertex.1, vertex.2, 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) let c = CGPoint(x: CGFloat(v), y: CGFloat(u)) textCords.append(c) } let textureSource = SCNGeometrySource(textureCoordinates: textCords) let normalsSource = SCNGeometrySource(meshAnchor.geometry.normals, semantic: .normal) let faceData = Data(bytes: faces.buffer.contents(), count: faces.buffer.length) let geometryElement = SCNGeometryElement(data: faceData, primitiveType: .triangles, primitiveCount: faces.count, bytesPerIndex: faces.bytesPerIndex) let nodeGeometry = SCNGeometry(sources: [vertexSource, textureSource, normalsSource], elements: [geometryElement]) let material = SCNMaterial() material.isDoubleSided = true let skScene = SKScene(size: CGSize(width: SPRITE_SIZE, height: SPRITE_SIZE)) skScene.backgroundColor = .clear material.diffuse.contents = skScene nodeGeometry.materials = [material] return nodeGeometry }