我有一个通过程序创建的平面,我想要获取其中一个顶点的坐标。类似这样:
这是我创建平面的方式:
print(Plane.vertices[1].position)
它可能会打印出像这样的结果:(x: 1, y: 1),而print(Plane.vertices[2].position)
则会打印 (x - 1, y: 1)。这是我创建平面的方式:
let positions = [SCNVector3Make( 0, -0.1, 0),
SCNVector3Make( 0.3, -0.1, 0),
SCNVector3Make( 0, 0.1, 0),
SCNVector3Make( 0.3, 0.1, 0),
]
let indices :[UInt16] = [
0, 1, 2,
1, 3, 2,
]
let vertexSource = SCNGeometrySource(vertices: positions, count: 4)
let indexData = NSData(bytes: indices, length: MemoryLayout<CInt>.size * indices.count)
let newElement = SCNGeometryElement(data: NSData(bytes: indices, length: indices.count * MemoryLayout<Int16>.size) as Data, primitiveType: .triangles , primitiveCount: 2, bytesPerIndex: MemoryLayout<Int16>.size)
let geometry = SCNGeometry(sources: [vertexSource], elements: [newElement])
custom = SCNNode(geometry: geometry)
scene.rootNode.addChildNode(custom!)
custom?.position = SCNVector3Make(0, 0, 0)
我认为可以通过transform来实现,但是自定义transform有很多奇怪的东西,比如m11、m12、m13,我不理解。