【问题标题】:SceneKit With Vuforia AR library custom modelsSceneKit 与 Vuforia AR 库自定义模型
【发布时间】:2017-12-11 15:01:58
【问题描述】:

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

有什么想法吗?谢谢

【问题讨论】:

    标签: ios swift swift3 scenekit vuforia


    【解决方案1】:

    我已经设法fix 一个问题。

    密钥在“texture.png”文件中。

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-09
      • 1970-01-01
      • 2014-12-25
      • 1970-01-01
      • 2020-09-28
      • 1970-01-01
      相关资源
      最近更新 更多