首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SCNGeometry不使用数据

SCNGeometry不使用数据
EN

Stack Overflow用户
提问于 2020-07-28 06:27:54
回答 1查看 95关注 0票数 0

我在网上找不到任何示例,显示不使用SCNGeometry / NSData/Data API为Data创建三角形的正确方法。我试着这样做,但没有任何东西呈现:

代码语言:javascript
复制
    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
    }
EN

回答 1

Stack Overflow用户

发布于 2022-11-25 17:04:51

注意索引的Int32

将不起作用:

代码语言:javascript
复制
    let indices = [0,1,2] 

作品:

代码语言:javascript
复制
    let indices: [Int32] = [0,1,2] 
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63128215

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档