gpt4 book ai didi

swift - 如何比较场景套件中两个球体的大小?

转载 作者:行者123 更新时间:2023-11-28 06:37:41 24 4
gpt4 key购买 nike

我的项目中有 2 个球体在同一位置。 firstSphere 较小,tempSphere 较大。

编辑:firstShape 会比 tempShape 大。当我暂停 firstShape 时,我正在尝试像“if firstShape.scale == tempShape.scale”这样的测试

//Create Shape
let firstShapeGeo = SCNSphere(radius: shapeRadius)
firstShape.geometry = firstShapeGeo
let shapeMaterial = SCNMaterial()
shapeMaterial.diffuse.contents = UIColor(colorLiteralRed: 0.2, green: 0.8, blue: 0.9, alpha: 1.0)
firstShapeGeo.materials = [shapeMaterial]
firstShape.position = SCNVector3Make(0, 0, 0)
scene.rootNode.addChildNode(firstShape)
firstShape.name = "\(shapeNumber)"

// Create Temp Shape
tempShapeRadius = shapeRadius + 1.0

let tempShapeGeo = SCNSphere(radius: tempShapeRadius)
tempShape.geometry = tempShapeGeo
let tempShapeMaterial = SCNMaterial()
tempShapeMaterial.diffuse.contents = UIColor(colorLiteralRed: 0.2, green: 0.8, blue: 0.9, alpha: 0.5)
tempShapeGeo.materials = [tempShapeMaterial]
firstShape.position = SCNVector3Make(0, 0, 0)
scene.rootNode.addChildNode(tempShape)

这就是我种植 firstSphere 的方式

let grow = SCNAction.scale(to: tempShapeRadius * 2 + 1, duration: 1)
let shrink = SCNAction.scale(to: tempShapeRadius, duration: 1)

let sequence = SCNAction.sequence([grow, shrink])
firstShape.run(SCNAction.repeatForever(sequence))

较小的球体通过使用 SCNAction.scale 变大,所以我不相信半径实际上在改变。不确定这是否是您需要了解的内容。

任何帮助将不胜感激!谢谢!

最佳答案

为两个球体分配相同的半径。将 tempShapescale 设置为比 firstShape 的初始值大所需数量的任何值。现在您只需要比较 scale

假设您希望 tempShape 球体的大小是可调整球体的 3 倍。

let tempScale: CGFloat = 3.0
tempShape.scale = SCNVector3(tempScale, tempScale, tempScale)
// grow from 1 to tempScale, then back to 1
let grow = SCNAction.scaleTo(tempScale, duration: 1)
let shrink = SCNAction.scaleTo(1, duration: 1)
let sequence = SCNAction.sequence([grow, shrink])
firstShape.run(SCNAction.repeatForever(sequence))

关于swift - 如何比较场景套件中两个球体的大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38735152/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com