Dienstag, 29. November 2016

SWIFT 3 SCENEKIT IOS SCNGeometry Geometrie von Hand erzeugen.

func Quad() -> SCNGeometry {

    let verticesPosition = [
        SCNVector3Make( -2, -2, 3),
        SCNVector3Make2, -2, 3),
        SCNVector3Make22, 3),
        SCNVector3Make( -22, 3)
    ]
    let textureCord =    [CGPoint(x: 0.0,y: 0.1),
                          CGPoint(x: 0.1,y: 0.1),
                          CGPoint(x: 0.1,y: 0.0),
                          CGPoint(x: 0.0,y: 0.0)]
    
    let indices: [CInt] = [
        0, 2, 3,
        0, 1, 2
    ]
    
    let vertexSource = SCNGeometrySource(vertices: verticesPosition, count: 4)
    let srcTex = SCNGeometrySource(textureCoordinates: textureCord, count: 4)
    let date = NSData(bytes: indices, length: MemoryLayout<CInt>.size * indices.count)
    
    let scngeometry = SCNGeometryElement(data: date as Data, primitiveType: SCNGeometryPrimitiveType.triangles, primitiveCount: 2, bytesPerIndex: MemoryLayout<CInt>.size)
    
    let geometry = SCNGeometry(sources: [vertexSource,srcTex], elements: [scngeometry])

    return geometry


}

Keine Kommentare:

Kommentar veröffentlichen