首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Swift 3中显示图像而不是SCNSphere?

如何在Swift 3中显示图像而不是SCNSphere?
EN

Stack Overflow用户
提问于 2017-09-23 15:31:13
回答 2查看 1.2K关注 0票数 0

我正在创建一个应用程序,其中我有一个SCNSphere显示,但出于某种原因,我试图找出如何从我的资产图像,而不是使用内置的几何,苹果的。因此,我的问题是如何在我的SceneKit应用程序而不是SCNSphere中显示一个图像。谢谢你的帮助。

代码语言:javascript
复制
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) 
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-09-23 16:07:21

如果您希望节点由SceneKit呈现,那么首先必须将几何数据(请参阅SCNGeometry类)附加到它。

SceneKit已经为您提供了一些这样的功能,使用SCNPlane,您可以使用飞机显示您想要的图像。

然后,您必须给节点一个显示图像的材料。

与此类似的可能是:

代码语言:javascript
复制
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

不要犹豫,要问具体的细节

票数 3
EN

Stack Overflow用户

发布于 2017-09-23 16:06:15

而不是SCNSphere创建一个SCNPlane,向其添加一个SCNMaterial并将其.diffuse.contents设置为图像。

另外,为了确保图像面向摄像机,向SCNPlane节点添加一个SCNPlane约束,使其能够查看摄像机(目标是所查看视图的pointOfView节点)。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46381241

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档