.obj文件未加载所有子网格名称

时间:2018-01-31 13:40:03

标签: xcode scenekit

这里,我正在使用带有.obj模型的SceneKit。我需要一些帮助来获取SceneKit.ModelIO的parts / submesh名称。

是否可以获取.obj的所有网格名称?请检查以下代码。

     // Here Obj url
    let url = "https://s3.ap-south-1.amazonaws.com/p9-platform/DAE/barware_s11624.obj"    
    let asset = MDLAsset(url: url as URL)
    let scene = SCNScene(mdlAsset: asset)
    let mesh = asset.object(at:0) as! MDLMesh
    let vertexBuffer = mesh.vertexBuffers[0]
    let descripter = mesh.vertexDescriptor
    let submeshes = mesh.submeshes

    for index in 0...(submeshes?.count)! - 1{

     let submesh0 = submeshes![index] as! MDLSubmesh

     let singleMesh = MDLMesh(vertexBuffer: vertexBuffer, vertexCount: mesh.vertexCount, descriptor: descripter, submeshes:  [submesh0])

     let geometry = SCNGeometry(mdlMesh: singleMesh)

     let Node = SCNNode(geometry: geometry)

     scene.rootNode.addChildNode(Node)
   }
   print("scene ===>\(scene.rootNode)")  

   //Print scene Result in Xcode console               
   scene ===><SCNNode: 0x1c41ef300 | 7 children>

   print("object.childNodes==>\(object.childNodes)")

   //Print object.childNodes Result  

这是Xcode控制台中的输出。

object.childNodes==>[<SCNNode: 0x1c41e9300 'default' | geometry=<SCNGeometry: 0x1c5339280 'default' | 6 elements> | no child>, <SCNNode: 0x1c41f5a00 | geometry=<SCNGeometry: 0x1c5339320 'Obj1'> | no child>, <SCNNode: 0x1c41f5b00 | geometry=<SCNGeometry: 0x1c53393c0 'Obj2'> | no child>, <SCNNode: 0x1c41f5d00 | geometry=<SCNGeometry: 0x1c5339460 'Obj3'> | no child>, <SCNNode: 0x1c41f5e00 | geometry=<SCNGeometry: 0x1c5339500 'Obj4'> | no child>, <SCNNode: 0x1c41f5f00 | geometry=<SCNGeometry: 0x1c53395a0 'Obj5'> | no child>, <SCNNode: 0x1c01f3c00 | geometry=<SCNGeometry: 0x1c0522260 'Obj6'> | no child>]

我想要相同的输出。

enter image description here

1 个答案:

答案 0 :(得分:0)

this question一样,我的建议是使用Assimp加载文件,它应该加载所有数据,并让您更好地控制如何处理它。