Ios 如何在Swift 3中显示图像而不是SCN?
我正在创建一个应用程序,其中显示了一个SCNSphere,但出于某种原因,我试图找出如何从我的资产中放置图像,而不是使用苹果公司的内置几何体。所以,我的问题是如何在SceneKit应用程序中显示图像,而不是在SCNSphere中显示。 谢谢你的帮助Ios 如何在Swift 3中显示图像而不是SCN?,ios,swift,scenekit,Ios,Swift,Scenekit,我正在创建一个应用程序,其中显示了一个SCNSphere,但出于某种原因,我试图找出如何从我的资产中放置图像,而不是使用苹果公司的内置几何体。所以,我的问题是如何在SceneKit应用程序中显示图像,而不是在SCNSphere中显示。 谢谢你的帮助 let personGeo = SCNSphere(radius: 0.2) person = SCNNode(geometry: personGeo) let personMat = SCNMaterial() personMat.diffuse
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)
创建SCNPlane时,将SCN材质添加到其中,并将其.diffuse.contents设置为图像,而不是SCN
此外,要确保图像面向摄影机,请向SCNPlane节点添加注视约束,使其注视摄影机(目标是sceneview的pointOfView节点)。创建SCNPlane时,请向其添加SCN材质,并将其.diffuse.contents设置为图像,而不是SCN
此外,为了确保图像面向摄影机,请向SCNPlane节点添加“注视”约束,使其注视摄影机(目标是sceneview的“视点”节点)。如果希望由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
请随时询问具体细节如果希望节点由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
请毫不犹豫地询问具体细节您到底想做什么?为了更改SceneKit显示的对象类型,您必须将personGeo设置为另一种SCNGeometry,例如SCNplane。我要做的是,不放置内置几何体,而是将我的资源中的图像显示出来。有办法吗?你到底想做什么?为了更改SceneKit显示的对象类型,您必须将personGeo设置为另一种SCNGeometry,例如SCNplane。我要做的是,不放置内置几何体,而是将我的资源中的图像显示出来。有办法吗?你能给我看一些代码来应用
SCNPlane
来显示图像吗?@user8651879我更新了关于如何创建材质和平面的答案:)@用户8651879不客气!如果答案对你有帮助,别忘了接受并提高投票率!:)你能给我看一些代码来应用SCNPlane
来显示图像吗?@user8651879我更新了我关于如何创建材质和平面的答案:)@用户8651879不客气!如果答案对你有帮助,别忘了接受并提高投票率!:)