xcode swift iOS sceneKit 导入外部dae - lightNode

📅 2026-12-01 👤 拼多多助力营销技巧 📂 拼多多助力 👁️ 261 次阅读

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文件所在目录下

参考链接,xcode

标签: 拼多多助力网站平台 赚钱项目 拼多多助力网 首码项目 手赚APP
拼多多助力营销技巧