首页 > 解决方案 > SCNGeometry 不使用数据

问题描述

我在网上找不到任何示例,显示正确创建SCNGeometry不使用NSData/ DataAPI 的三角形。我正在尝试这样做,但没有任何渲染:

    func
    testTriangles()
        -> SCNNode
    {
        //  Vertices…
        
        var vertices = [SCNVector3]()
        vertices.append(SCNVector3(x: 0.0, y: 0.0, z: 0.0))
        vertices.append(SCNVector3(x: 0.0, y: 0.0, z: 50.0))
        vertices.append(SCNVector3(x: 50.0, y: 0.0, z: 50.0))
        let vertexSource = SCNGeometrySource(vertices: vertices)
        
        var normals = [SCNVector3]()
        normals.append(SCNVector3(x: 0.0, y: 1.0, z: 0.0))
        normals.append(SCNVector3(x: 0.0, y: 1.0, z: 0.0))
        normals.append(SCNVector3(x: 0.0, y: 1.0, z: 0.0))
        let normalSource = SCNGeometrySource(normals: normals)
        
        //  Indices…
        
        var indices = [0, 1, 2]
        let triangles = SCNGeometryElement(indices: indices, primitiveType: .triangles)
        
        let geom = SCNGeometry(sources: [vertexSource, normalSource], elements: [triangles])
        
        let node = SCNNode()
        node.geometry = geom
        
        let mat = SCNMaterial()
        mat.diffuse.contents = NSColor.green
        geom.materials = [mat]
        
        return node
    }

标签: swiftmacosscenekit

解决方案


推荐阅读