SceneKit 与 Vuforia AR 库自定义模型

SceneKit With Vuforia AR library custom models

我是 SceneKit 的新人,正在使用 swift 3 和最新的 Vuforia 图书馆 6-2-9。

我在自定义 3D 模型上应用 textures 时遇到问题。

fileprivate func createDefaultMarkerScene(with view: VuforiaEAGLView) -> SCNScene {
    let scene = SCNScene()

    let lightNode = SCNNode()
    lightNode.light = SCNLight()
    lightNode.light?.type = .omni
    lightNode.light?.color = UIColor.lightGray
    lightNode.position = SCNVector3(x: 0, y: 0, z: 1000)
    scene.rootNode.addChildNode(lightNode)

    let ambientLightNode = SCNNode()
    ambientLightNode.light = SCNLight()
    ambientLightNode.light?.type = .ambient
    ambientLightNode.light?.color = UIColor.darkGray
    scene.rootNode.addChildNode(ambientLightNode)

    let geoNode = SCNNode()
    geoNode.name = "model_model"

    let normalsSources = SCNGeometrySource(normals: normalsSCNVector3)
    let verticesSources = SCNGeometrySource(vertices: verticesSCNVector3)
    let texCoordsSources = SCNGeometrySource(textureCoordinates: texCoordCGPoint)
    let indicesElements = SCNGeometryElement(indices: indices, primitiveType: SCNGeometryPrimitiveType.triangles)

    geoNode.geometry = SCNGeometry(sources: [verticesSources, normalsSources, texCoordsSources], elements: [indicesElements])
    geoNode.position = SCNVector3(x: 0, y: 0, z: 0)
    geoNode.scale = SCNVector3(x: 50, y: 50, z: 50)

    let material = SCNMaterial()

    material.diffuse.contents = UIImage(named: "grad_ao.png")

    geoNode.geometry?.firstMaterial = material

    scene.rootNode.addChildNode(geoNode)

    return scene
}

模型已正确渲染,但应用的纹理完全混乱。我尝试过旋转图像,uv 坐标也都可以 [0..1].

有什么想法吗?谢谢

我已设法 fix 一个问题。

密钥在 "texture.png" 文件中。

我只需要将图像翻转 180 度:

material.diffuse.contentsTransform = SCNMatrix4Translate(SCNMatrix4MakeScale(1, -1, 1), 0, 1, 0)