简体   繁体   中英

If I allocate MDLAsset using metal, then inititialize an SCNNode using that asset, are the SCNGeometrySource objects copied to non-Metal buffers?

If I allocate an MDLAsset and SCNNode like so

let device: MTLDevice = (sceneView?.device)!
let allocator = MTKMeshBufferAllocator(device: device)
let url = Bundle.main.url(forResource: name, withExtension: "obj")
let asset = MDLAsset(url: url! as URL, vertexDescriptor: nil, bufferAllocator: allocator)

guard let object = asset.object(at: 0) as? MDLMesh else {
      print("Failed to get mesh from obj asset")
      return nil
}

let node = SCNNode.init(mdlObject: object)
let geometrySources = node.geometry.sources

Are my geometrySource objects backed by Metal buffers, or has the process gone and copied the data in NSData?

After experimentation, it is indeed the case that unless you explicitly initialize a SCNGeometrySource with a metal buffer it will be backed by a non-mutable NSData buffer. This is even if the obj file was loaded into an MDLAsset using an MTLMeshBufferAllocator in the initial setup.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM