玩我有充分的動畫工作OS X的例子,開始,暫停,變化速度等SceneKit動畫不會在iOS中
現在我開始這個移植到iOS甚至不能啓動動畫。我將代碼簡化到最低限度 - 它在OS X中可用,但不適用於iOS。
我做的是
- 顯示一個場景中有一個(動畫)字符(空閒動畫) - 無論是在OS X和iOS
- 開始對角色運行動畫作品。這適用於OS X,運行動畫開始和循環。在iOS上,角色位於運行動畫開始處。但它不運行...
如果我從例如運行場景而不是閒置,它可以工作 - 角色運行。問題是當我在場景加載後開始動畫(任何)時。它用動畫加載模型但不播放。
的OS X和iOS版本之間的詳細比較後,我發現2倍的差異,這可能是相關的,但我無法弄清楚如何解決這些問題:
在OS X版本的字符不是動畫直到我開始動畫。在iOS版本中,當我將空閒節點(或任何其他場景)附加到根節點時,它是動畫的。我不知道如何改變這一點。
OS X版本的scene.dae附加到故事板中的場景視圖 - iOS中也是如此。但在iOS出於某種原因,這個附件不起作用,'self.scene'爲零。這就是爲什麼我必須以編程方式實例化和分配場景。我不能修復它,試圖重新添加場景視圖,分配出口等
場景套件視圖中使用的故事板中的溶液。閒置並運行.dae文件。他們每個人都包含一個完整的角色模型和動畫。我再次檢查動畫標識符是否與.dae文件中的相同。實際上,從蘋果公司的例子提供的模型和OS X完美地工作......
這是代碼:
視圖控制器:
#import "ViewController.h"
@interface ViewController()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
}
- (void)viewDidAppear:(BOOL)animated {
[self.sceneView loadScene];
}
@end
場景套件視野頭:
// ASCView.h
#import <UIKit/UIKit.h>
#import <SceneKit/SceneKit.h>
@interface ASCView : SCNView
- (void)loadScene;
@end
現場套件視圖執行:
//
// ASCView.m
// anim_test
//
//
#import "ASCView.h"
@implementation ASCView
- (void)loadScene {
self.backgroundColor = [UIColor blueColor];
self.allowsCameraControl = YES;
[self loadSceneAndAnimations];
}
#pragma mark - Animation loading
- (void)loadSceneAndAnimations {
// Load the character from one of our dae documents, for instance "idle.dae"
NSURL *idleURL = [[NSBundle mainBundle] URLForResource:@"idle" withExtension:@"dae"];
SCNScene *idleScene = [SCNScene sceneWithURL:idleURL options:nil error:nil];
SCNScene *scene = [SCNScene sceneNamed:@"scene.dae"];
self.scene = scene;
NSLog(@"scene: %@", self.scene);
// Merge the loaded scene into our main scene in order to
// place the character in our own scene
for (SCNNode *child in idleScene.rootNode.childNodes)
[self.scene.rootNode addChildNode:child];
// Load and start run animation
// The animation identifier can be found in the Node Properties inspector of the Scene Kit editor integrated into Xcode
[self loadAndStartAnimation:@"run" withIdentifier:@"RunID"];
}
- (void)loadAndStartAnimation:(NSString *)sceneName withIdentifier:(NSString *)animationIdentifier {
NSURL *sceneURL = [[NSBundle mainBundle] URLForResource:sceneName withExtension:@"dae"];
SCNSceneSource *sceneSource = [SCNSceneSource sceneSourceWithURL:sceneURL options:nil];
CAAnimation *animationObject = [sceneSource entryWithIdentifier:animationIdentifier withClass:[CAAnimation class]];
NSLog(@"duration: %f", [animationObject duration]); //0.9
animationObject.duration = 1.0;
animationObject.repeatCount = INFINITY;
[self.scene.rootNode addAnimation:animationObject forKey:@"foofoofoo"];
NSLog(@"animation: %@",[self.scene.rootNode animationForKey: @"foofoofoo"]);
NSLog(@"is paused: %@",[self.scene.rootNode isAnimationForKeyPaused: @"foofoofoo"] ? @"yes" : @"no"); //NO
}
@end