swift iOS sceneKit 导入外部dae

1、用blender把fbx改成 dae导出

2、在ios工程目录里随便建一个资源文件夹

3、代码

var gap = 0

        let window = UIApplication.shared.windows.first

        var topPadding = window?.safeAreaInsets.top ?? 0

        topPadding += navigationController?.navigationBar.frame.height ?? 0

        topPadding += (CGFloat)(gap);

        

        var tabBarH:CGFloat = navigationController!.tabBarController!.tabBar.frame.height

        var height = UIScreen.main.bounds.height - topPadding - tabBarH

        

        let scene = SCNScene()

        //let scene = SCNScene(named: "3DGameScene")

        let sceneView = SCNView(frame:CGRect(x:0,y:topPadding,width:UIScreen.main.bounds.width,height:height))

        sceneView.backgroundColor = UIColor.white

        sceneView.scene = scene;

        self.view.addSubview(sceneView)

        

        let camera = SCNCamera()

        let cameraNode = SCNNode()

        cameraNode.camera = camera

        cameraNode.position = SCNVector3(x: 0.0, y: 0.0, z: 3.0)

         

        let light = SCNLight()

        light.type = SCNLight.LightType.omni

        let lightNode = SCNNode()

        lightNode.light = light

        lightNode.position = SCNVector3(x: 1.5, y: 1.5, z: 1.5)

         

        let cubeGeometry = SCNBox(width: 1.0, height: 1.0, length: 1.0, chamferRadius: 0.0)

        let cubeNode = SCNNode(geometry: cubeGeometry)

        

        

        //scene.rootNode.addChildNode(cubeNode)

        scene.rootNode.addChildNode(lightNode)

        scene.rootNode.addChildNode(cameraNode)

        guard  let url = Bundle.main.url(forResource: "r2", withExtension: "dae") else {

            fatalError("baby_groot.dae not exit.")

        }

        guard let customNode = SCNReferenceNode(url: url) else {

            fatalError("load baby_groot error.")

        }

        customNode.load()

        print(customNode)

        customNode.position = SCNVector3(x: 0, y: 0, z: 0)

        scene.rootNode.addChildNode(customNode)

5、重新绑定纹理

把纹理图放到dae文件所在目录下

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值