SceneKit加载.scn和.dae模型

加载.scn模型

加载ios自带的ship.scn模型,取scn里面名为ship的子节点,纹理设置为texture.png,设置纹理的时候如果写"texture.jpg"还是会默认去找"texture.png",可能SceneKit纹理只能是png格式。

NSURL *bundlePathUrl = [[NSBundle mainBundle] bundleURL];
bundlePathUrl = [bundlePathUrl URLByAppendingPathComponent:@"ship.scn"];
SCNScene *scene=[SCNScene sceneWithURL:bundlePathUrl options:nil error:nil];
SCNNode *shipNode=[scene.rootNode childNodeWithName:@"ship" recursively:YES];
shipNode.geometry.firstMaterial.diffuse.contents=@"texture";

加载.dae模型

加载我的skinning.dae模型,里面有一个名为avatar_attach的模型,拿出来当作SCNNode即可以设置position等信息。

SCNSceneSource *sceneSource = [SCNSceneSource sceneSourceWithURL:[[NSBundle mainBundle] URLForResource:@"skinning" withExtension:@".dae"] options:nil];
SCNScene *scene=[sceneSource sceneWithOptions:nil error:nil];
SCNNode *robotBode=[scene.rootNode childNodeWithName:@"avatar_attach" recursively:YES];
robotBode.position=SCNVector3Make(0, 0, -5000);
[_scnView.scene.rootNode addChildNode:robotBode];

你可能感兴趣的:(ios开发,SceneKit)