2016-11-17 4 views
1

SceneKitでカスタムジオメトリを作成できましたが、常に反転/反転テクスチャが表示されます。SceneKitカスタムジオメトリで常にテクスチャが反転して反転した

私はカスタムジオメトリのための他の人のサンプルコードを試しましたが、フリップ/反転テクスチャの問題で終わりました。どんな助けでも大歓迎です!

flipped/inverted texture screenshot

// v1 +----+ v0 
    // | | 
    // v2 +----+ v3 

let positions: [Float] = [ 
    5.0, 5.0, 0.0, 
    -5.0, 5.0, 0.0, 
    -5.0, -5.0, 0.0, 
    5.0, -5.0, 0.0 
] 

let normals: [Float] = [ 
    0.0, 0.0, 1.0, 
    0.0, 0.0, 1.0, 
    0.0, 0.0, 1.0, 
    0.0, 0.0, 1.0 
] 

let tcoords: [Float] = [ 
    1.0, 1.0, 
    0.0, 1.0, 
    0.0, 0.0, 
    1.0, 0.0 
] 

let positionsData = Data(bytes: positions, count: positions.count * 4) 

let positionSource = SCNGeometrySource(data: positionsData, 
             semantic: SCNGeometrySource.Semantic.vertex, 
             vectorCount: positions.count/3, 
             usesFloatComponents: true, 
             componentsPerVector: 3, 
             bytesPerComponent: 4, 
             dataOffset: 0, 
             dataStride: 12) 

let normalsData = Data(bytes: normals, count: normals.count * 4) 

let normalSource = SCNGeometrySource(data: normalsData, 
             semantic: SCNGeometrySource.Semantic.normal, 
             vectorCount: normals.count/3, 
             usesFloatComponents: true, 
             componentsPerVector: 3, 
             bytesPerComponent: 4, 
             dataOffset: 0, 
             dataStride: 12) 

let tcoordsData = Data(bytes: tcoords, count: tcoords.count * 4) 

let tcoordSource = SCNGeometrySource(data: tcoordsData, 
            semantic: SCNGeometrySource.Semantic.texcoord, 
            vectorCount: tcoords.count/2, 
            usesFloatComponents: true, 
            componentsPerVector: 2, 
            bytesPerComponent: 4, 
            dataOffset: 0, 
            dataStride: 8) 

let index: [UInt8] = [0,1,2,0,2,3] 

let indexData = Data(bytes: index, count: index.count) 

let indexElement = SCNGeometryElement(data: indexData, 
             primitiveType: SCNGeometryPrimitiveType.triangles, 
             primitiveCount: index.count/3, 
             bytesPerIndex: 1) 

let geometry = SCNGeometry(sources: [positionSource, normalSource, tcoordSource], 
          elements: [indexElement]) 

答えて

2

あなたはtcoordsにテクスチャ座標を反転することをお勧めします。 SceneKitは、conventionに続いて、テクスチャ座標の原点がテクスチャの左上にあることを示します。

メタルでは、フレームバッファアタッチメントのピクセル座標系の原点が左上隅に定義されています。同様に、フレームバッファアタッチメントのピクセル座標系の原点は左上隅です。

+0

OMG、私はグーグルで、1週間以上私自身でこれを理解しようとしています。私はいつもlurkerだった、私は通常質問を投稿しません。あなたのソリューションは完璧に機能しました!あなたは人生の節約者です、私はそれを私のFBXをSceneKitインポータツールの開発を終了すると呼ぶつもりでしたが、今は続けることができます! – Phi