ios - SceneKit 与 Vuforia AR 库自定义模型

标签 ios swift swift3 scenekit vuforia

我是 SceneKit 的新手,正在使用 swift 3 和最新的 Vuforia 库 6-2-9。

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

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]。

有什么想法吗?谢谢

Textures are messed up

最佳答案

我已成功解决一个问题。

key 位于“texture.png”文件中。

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

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

关于ios - SceneKit 与 Vuforia AR 库自定义模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44968649/

相关文章:

ios - Objective-c 中的 const 修饰符

ios - 多个完成 block 完成后执行的函数

ios - 通过多点连接跟踪 NSProgress 的变化

swift - 连续滚动的背景

xcode - 如何交互地玩 Xcode lldb swift repl 中的对象?

ios - dispatch_once 转换 Swift 3

php - 如何在Swift 3.0中将JSON数据提取到UIPickerView中?

swift - 将 Int 转换为 Bool

ios - Objective C,在堆栈跟踪中不涉及我的应用程序时处理崩溃报告

ios - 在 Swift 中访问堆栈上的 View Controller 数组