[英]SceneKit – Playing DAE and USDZ animation using Objective-C
我想在 SceneKit 中創建步行人動畫。 我正在從 3DSMax + OpenCollada 導出動畫 .dae 文件,我還使用ConvertToXcodeCollada將所有動畫合二為一。 我如何獲得動畫:
SCNScene *humanScene = [SCNScene sceneNamed:@"art.scnassets/myScene.DAE"];
CAAnimation *Animation = [[humanScene rootNode] animationForKey:@"myScene-1"];
我也嘗試從“SCNSceneSource”獲取動畫
我如何添加動畫:
SCNNode *humanNode = [humanScene.rootNode childNodeWithName:@"myScene-1" recursively:YES];
[humanNode addAnimation:walkingAnimation forKey:@"myScene-1"];
或者:
SCNNode* humanNode = [SCNNode new];
for(SCNNode* node in humanScene.rootNode.childNodes){
[humanNode addChildNode:node];
}
[humanNode addAnimation:walkingAnimation forKey:@"myScene-1"];
我的對象“walkingAnimation”是“CAAnimationGroup”。
但它在應用程序中沒有動畫。 我只能在 Xcode sceneKit 編輯器中看到動畫。
使用您的模型嘗試以下代碼。 有用。 我在 macOS 12.1 中使用了 Xcode 13.2.1。
首先填充
viewDidLoad<\/code>方法:
#import "GameViewController.h"
@implementation GameViewController
SCNView *sceneView;
bool notRunningSwitch;
NSMutableDictionary<NSString*, CAAnimation*> *animations;
SCNNode *node;
- (void)viewDidLoad
{
[super viewDidLoad];
sceneView = (SCNView *)self.view;
notRunningSwitch = YES;
animations = @{}.mutableCopy;
node = [SCNNode node];
SCNScene *scene = [SCNScene scene];
sceneView.scene = scene;
sceneView.autoenablesDefaultLighting = YES;
sceneView.allowsCameraControl = YES;
[self anime];
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.