我在网上找不到任何示例,显示不使用SCNGeometry / NSData/Data API为Data创建三角形的正确方法。我试着这样做,但没有任何东西呈现:
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
}发布于 2022-11-25 17:04:51
注意索引的Int32
将不起作用:
let indices = [0,1,2] 作品:
let indices: [Int32] = [0,1,2] https://stackoverflow.com/questions/63128215
复制相似问题