我正在创建一个应用程序,其中我有一个SCNSphere显示,但出于某种原因,我试图找出如何从我的资产图像,而不是使用内置的几何,苹果的。因此,我的问题是如何在我的SceneKit应用程序而不是SCNSphere中显示一个图像。谢谢你的帮助。
let personGeo = SCNSphere(radius: 0.2)
person = SCNNode(geometry: personGeo)
let personMat = SCNMaterial()
personMat.diffuse.contents = UIColor.cyan
personGeo.materials = [personMat]
person.position = SCNVector3Make(0, 1.1, 0)
person.physicsBody = SCNPhysicsBody(type: SCNPhysicsBodyType.static, shape: SCNPhysicsShape(node: person, options: nil))
person.physicsBody?.categoryBitMask = bodyNames.Person
person.physicsBody?.collisionBitMask = bodyNames.Coin
person.physicsBody?.contactTestBitMask = bodyNames.Coin
person.physicsBody?.isAffectedByGravity = false
scene.rootNode.addChildNode(person) 发布于 2017-09-23 16:07:21
如果您希望节点由SceneKit呈现,那么首先必须将几何数据(请参阅SCNGeometry类)附加到它。
SceneKit已经为您提供了一些这样的功能,使用SCNPlane,您可以使用飞机显示您想要的图像。
然后,您必须给节点一个显示图像的材料。
与此类似的可能是:
let scene = SCNScene(named: "art.scnassets/ship.scn")!
let image = UIImage(named: "nameOfYourImage")!
let imageRatio = image.size.height / image.size.width
let desiredPlaneWidth: CGFloat = 1
let planeGeometry = SCNPlane(width: desiredPlaneWidth, height: desiredPlaneWidth*imageRatio) // We make a plane that has the same aspect ratio as the image we want to display with it
let planeMaterial = SCNMaterial()
planeMaterial.emission.contents = image // Emission makes
planeMaterial.isDoubleSided = true // Otherwise plane would only be visible from one side不要犹豫,要问具体的细节
发布于 2017-09-23 16:06:15
而不是SCNSphere创建一个SCNPlane,向其添加一个SCNMaterial并将其.diffuse.contents设置为图像。
另外,为了确保图像面向摄像机,向SCNPlane节点添加一个SCNPlane约束,使其能够查看摄像机(目标是所查看视图的pointOfView节点)。
https://stackoverflow.com/questions/46381241
复制相似问题