2017-07-07 25 views
0

我是SceneKit中的新產品,使用swift 3和最新的Vuforia庫6-2-9。Sceneikit使用Vuforia AR庫定製型號

我在自定義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座標一切ok [0..1]。

任何想法?謝謝

Textures are messed up

回答

0

我已成功地fix的問題。

關鍵在「texture.png」文件中。

我只需要翻轉圖像180度:

material.diffuse.contentsTransform = SCNMatrix4Translate(SCNMatrix4MakeScale(1, -1, 1), 0, 1, 0) 
相關問題