SCNTransaction repetition

huangapple go评论66阅读模式
英文:

SCNTransaction repetition

问题

以下是翻译好的代码部分:

以下函数接受一个 SCNNode 参数,并使用 SCNAction 连续重复旋转:

func scnActionFunc(nodeParam: inout SCNNode) {
   let angleAmount: CGFloat = 360 * ((.pi) / 180.0)
   let action = SCNAction.rotate(by: angleAmount, around: SCNVector3(x: 0, y: 1, z: 0), duration: 32.0)
   let repeatAction = SCNAction.repeatForever(action)
   nodeParam.runAction(repeatAction)
}

这第二个函数接受一个 SCNNode 参数,并使用 SCNTransaction 执行单个部分旋转:

func scnTransactionFunc(nodeParam: inout SCNNode) {
   SCNTransaction.begin()
   SCNTransaction.animationTimingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeOut)
   SCNTransaction.animationDuration = 3.0
   nodeParam.transform = SCNMatrix4MakeRotation(-(.pi / 2.0), 1, 0, 0)
   SCNTransaction.commit()
}

请注意,我只翻译了代码部分,没有包括问题部分。

英文:

The following function accepts a single SCNNode param and
it uses SCNAction to continuously repeat
a rotation:

   func scnActionFunc(nodeParam :inout SCNNode){
   let angleAmount : CGFloat = 360 * ((.pi)/180.0)
   let action = SCNAction.rotate(by: angleAmount, around: SCNVector3(x: 0, y: 1, z: 0) , duration: 32.0)
   let repeatAction = SCNAction.repeatForever(action)
   nodeParam.runAction(repeatAction)
   }

This second function accepts a single SCNNode param and
it uses SCNTransaction to perform a single partial rotation:

  func scnTransactionFunc(nodeParam:inout SCNNode){
  SCNTransaction.begin()
  SCNTransaction.animationTimingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeOut)
  SCNTransaction.animationDuration = 3.0
  nodeParam.transform = SCNMatrix4MakeRotation( -(.pi / 2.0), 1, 0, 0)
  SCNTransaction.commit()
  }

My questions:
1: as far as I can see, SCNTransaction does not have its own 'repeat' function - is this the case?
2: Im sure its possible to repeat an SCNTransaction in a function using Timer() or similar class but is there
A canonical method for repeating SCNTransaction code over and over?
Im not trying to find out about repetition itself - there are doubtlessly numerous methods of achieving repeated actions - My reason for posing this question is because Im just trying to make sure I properly understand SCNTransaction as fully as possible. Thanks.

答案1

得分: 0

据我了解,在SCNTransaction中没有内置的重复功能。你可能可以像这样使用:

// 带有完成处理程序的场景事务示例
SCNTransaction.begin()
SCNTransaction.animationDuration = 6.0
// 为完成处理启用 completionBlock
SCNTransaction.completionBlock = {
    SCNTransaction.begin()
    SCNTransaction.animationDuration = 1.0
    explosion.particleColor = UIColor.blue
    SCNTransaction.commit()
}
cameraNode.camera?.focalLength = 50
SCNTransaction.commit()

通过调用函数本身来替换completionBlock中的内容:

func scnTransactionFunc(nodeParam:inout SCNNode) {
    SCNTransaction.begin()
    SCNTransaction.animationTimingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeOut)
    SCNTransaction.animationDuration = 3.0

    SCNTransaction.completionBlock = {
        scnTransactionFunc(nodeParam:inout SCNNode)
    }

    nodeParam.transform = SCNMatrix4MakeRotation( -(.pi / 2.0), 1, 0, 0)
    SCNTransaction.commit()
}

**注意:直到退出应用程序,此函数将永远不会终止。**

也许最好使用你使用SCNAction的示例。这个可以随时终止。使用计划定时器也可能有效。

希望我能在某种程度上帮到你。

<details>
<summary>英文:</summary>

As far as I know, there is no built-in repeat functionality within SCNTransaction. You could use probably something like this:

    // Scene Transaction with completion handler example
    SCNTransaction.begin()
    SCNTransaction.animationDuration = 6.0
    // For completion handling - enable the completionBlock
    SCNTransaction.completionBlock = {
        SCNTransaction.begin()
        SCNTransaction.animationDuration = 1.0
        explosion.particleColor = UIColor.blue
        SCNTransaction.commit()
    }
    cameraNode.camera?.focalLength = 50
    SCNTransaction.commit()

replace the content of the completionBlock by calling the function itself again.

    func scnTransactionFunc(nodeParam:inout SCNNode) {
        SCNTransaction.begin()
        SCNTransaction.animationTimingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeOut)
        SCNTransaction.animationDuration = 3.0

        SCNTransaction.completionBlock = {
        scnTransactionFunc(nodeParam:inout SCNNode)
        }

        nodeParam.transform = SCNMatrix4MakeRotation( -(.pi / 2.0), 1, 0, 0)
        SCNTransaction.commit()
    }

**Note: this function will never terminate until you exit the application.**

It might be better to use the example in which you use the SCNAction. This one you can terminate at any time. Using a Scheduled Timer might work as well.

Hope I could help you in some way.

</details>



huangapple
  • 本文由 发表于 2023年6月29日 01:06:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/76575333.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定