0

iOS アプリではSceneKit .scn、単一のクワッドを含むファイルをロードし、そこから生成しようとしMTKMeshています。喜びはありません。

ファイルをロードしSCNSceneます:

guard let scene = SCNScene(named:"scenes.scnassets/quad.scn") else {
    fatalError("Error: Can not create SCNScene with \(sceneName)")
}

シーン グラフをトラバースしてクワッドを見つけます。

guard let sceneNode = scene.rootNode.childNode(withName:"quadIdentity", recursively:true) else {
    fatalError("Error: Can not create sceneNode")
}

クワッド ジオメトリを抽出します。

guard let sceneGeometry = sceneNode.geometry else {
    fatalError("Error: Can not create sceneGeometry")
}

Model I/Oジオメトリからメッシュを作成します。

let modelIOMesh = MDLMesh(scnGeometry:sceneGeometry, bufferAllocator:MTKMeshBufferAllocator(device:device))

Metal頂点の説明を次の形式に強制します。

let metalVertexDescriptor = MTLVertexDescriptor.xyz_n_st_vertexDescriptor()

let modelIOVertexDescriptor = MTKModelIOVertexDescriptorFromMetal(metalVertexDescriptor)
(modelIOVertexDescriptor.attributes[ 0 ] as! MDLVertexAttribute).name = MDLVertexAttributePosition
(modelIOVertexDescriptor.attributes[ 1 ] as! MDLVertexAttribute).name = MDLVertexAttributeNormal
(modelIOVertexDescriptor.attributes[ 2 ] as! MDLVertexAttribute).name = MDLVertexAttributeTextureCoordinate

modelIOMesh.vertexDescriptor = modelIOVertexDescriptor

これは常に失敗しますfatal error:

do {
    mesh = try MTKMesh(mesh:modelIOMesh, device:device)
} catch {
    fatalError("Error: Can not create Metal mesh")
}

私は何が欠けていますか?

更新 0

エラーを出力するように try/catch を変更します。

do {

    mesh = try MTKMesh(mesh:modelIOMesh, device:device)

} catch let error as NSError {

    print(error.localizedDescription)

}

エラーは次のとおりです。

致命的なエラー: オプション値のラップ解除中に予期せず nil が見つかりました

4

0 に答える 0