Skip to content

Commit

Permalink
Add rotation animation
Browse files Browse the repository at this point in the history
  • Loading branch information
nicklockwood committed Jul 26, 2024
1 parent c353154 commit 54e7972
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Viewer/Mac/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,11 @@
<action selector="selectCameras:" target="Ady-hI-5gd" id="HZd-JH-W4K"/>
</connections>
</menuItem>
<menuItem title="Animate Rotation" keyEquivalent="r" id="HOL-Bv-wDo">
<connections>
<action selector="toggleAnimation:" target="Ady-hI-5gd" id="YHc-yb-C38"/>
</connections>
</menuItem>
<menuItem title="Orthographic" keyEquivalent="O" id="B4E-h4-Tuy">
<connections>
<action selector="setOrthographic:" target="Ady-hI-5gd" id="Nmz-MT-00a"/>
Expand Down
6 changes: 6 additions & 0 deletions Viewer/Mac/Document.swift
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,10 @@ class Document: NSDocument {
viewController?.copyCamera()
}

@IBAction func toggleAnimation(_: Any? = nil) {
viewController?.isAnimating.toggle()
}

@IBAction func showWireframe(_: NSMenuItem) {
showWireframe.toggle()
}
Expand All @@ -426,6 +430,8 @@ class Document: NSDocument {

override func validateMenuItem(_ menuItem: NSMenuItem) -> Bool {
switch menuItem.action {
case #selector(toggleAnimation(_:)):
menuItem.state = (viewController?.isAnimating == true) ? .on : .off
case #selector(showWireframe(_:)):
menuItem.state = showWireframe ? .on : .off
case #selector(showAxes(_:)):
Expand Down
13 changes: 13 additions & 0 deletions Viewer/Mac/DocumentViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,19 @@ class DocumentViewController: NSViewController {
}
}

var isAnimating = false {
didSet {
if !isAnimating {
scnScene.rootNode.removeAllActions()
scnScene.rootNode.orientation = .init(x: 0, y: 0, z: 0, w: 0)
} else {
scnScene.rootNode.runAction(
.repeatForever(.rotateBy(x: 0, y: 1, z: 0, duration: 1))
)
}
}
}

var showAxes = false {
didSet {
if showAxes != oldValue {
Expand Down

0 comments on commit 54e7972

Please sign in to comment.