SceneKit加载.scn和.dae模型

本文介绍如何在iOS中使用SceneKit加载.scn和.dae模型,包括设置纹理、获取子节点及调整位置等关键步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

加载.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];
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值