Extracting vertices from scenekit

后端 未结 7 431
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-03 01:42

I\'m having a problem with understanding scenekit geometery.

I have the default cube from Blender, and I export as collada (DAE), and can bring it into scenekit....

7条回答
  •  时光取名叫无心
    2020-12-03 02:14

    The Swift Version

    The Objective-C version and this are essentially identical.

    let planeSources = _planeNode?.geometry?.geometrySourcesForSemantic(SCNGeometrySourceSemanticVertex)
    if let planeSource = planeSources?.first {
        let stride = planeSource.dataStride
        let offset = planeSource.dataOffset
        let componentsPerVector = planeSource.componentsPerVector
        let bytesPerVector = componentsPerVector * planeSource.bytesPerComponent
    
        let vectors = [SCNVector3](count: planeSource.vectorCount, repeatedValue: SCNVector3Zero)
        let vertices = vectors.enumerate().map({
            (index: Int, element: SCNVector3) -> SCNVector3 in
            var vectorData = [Float](count: componentsPerVector, repeatedValue: 0)
            let byteRange = NSMakeRange(index * stride + offset, bytesPerVector)
            planeSource.data.getBytes(&vectorData, range: byteRange)
            return SCNVector3Make(vectorData[0], vectorData[1], vectorData[2])
        })
    
        // You have your vertices, now what?
    }
    

提交回复
热议问题