【发布时间】:2019-11-08 00:40:39
【问题描述】:
我使用 SCNGeometrySource 创建了 SCNNode,使用自定义选择的 SCNVector3 点超过三个,并应用图像材质来显示非常拉伸的材质。如何在 SCNGeometrySource 节点上正确应用材质。
func getsquareDrawnLineFrom(pos1: SCNVector3,
pos2: SCNVector3,
pos3: SCNVector3) -> SCNNode {
let square = SquareplanlineFrom(vector1: pos1, vector2: pos2, vector3: pos3)
//SCNGeometrySource.Semantic.texcoord
//SCNGeometrySource.Semantic.normal
let material = SCNMaterial()
// material.diffuse.contents = UIColor.lightGray
material.diffuse.contents = UIImage(named: "grid")
material.diffuse.contentsTransform = SCNMatrix4MakeScale(32, 32, 0)
material.diffuse.wrapS = .repeat
material.diffuse.wrapT = .repeat
square.materials = [material]
let square1 = SCNNode(geometry: square)
square1.name = "tringle"
return square1
}
// get line geometry between two vectors
func SquareplanlineFrom(vector1: SCNVector3,
vector2: SCNVector3, vector3: SCNVector3) -> SCNGeometry {
let normalsPerFace = 3
let indices: [Int32] = [0, 1, 2]
let source = SCNGeometrySource(vertices: [vector1, vector2, vector3])
let normals:[SCNVector3] = [
vector1,
vector2,
vector3].map{[SCNVector3](repeating:$0,count:normalsPerFace)}.flatMap{$0}
let normalSource = SCNGeometrySource(normals: normals)
let cgp1 = CGPoint(x: CGFloat(vector1.x), y: CGFloat(vector1.y))
let cgp2 = CGPoint(x: CGFloat(vector2.x), y: CGFloat(vector2.y))
let cgp3 = CGPoint(x: CGFloat(vector3.x), y: CGFloat(vector3.y))
let textcoord = SCNGeometrySource(textureCoordinates: [cgp1,cgp2,cgp3])
// let texcoord = SCNGeometrySource(textureCoordinates: [])
// let normalSource = SCNGeometrySource(normals: [vector1, vector2, vector3])
let element = SCNGeometryElement(indices: indices,
primitiveType: .triangles)
return SCNGeometry(sources: [source,normalSource,textcoord], elements: [element])
}
【问题讨论】:
标签: ios swift scenekit augmented-reality arkit