从Blender导出到COLLADA / .dae格式时包含纹理,以便在SceneKit中使用 [英] Including textures when exporting from Blender to COLLADA/.dae format for use in SceneKit

查看:1163
本文介绍了从Blender导出到COLLADA / .dae格式时包含纹理,以便在SceneKit中使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用COLLADA / .dae格式导出在Blender中创建的网格,以便在SceneKit中使用 - 但iOS设备上不显示任何纹理。

I am able to export meshes created in Blender for use in SceneKit by using the COLLADA/.dae format - however no textures show up on iOS device.

,在OS X上预览不会打开从Blender导出的任何COLLADA文件 - 但侧边栏预览显示网格。导出所需的选项有哪些?

Also, Preview on OS X won't open any COLLADA file exported from Blender - yet the sidebar preview does show the mesh. What are the options needed at export to make this work?

推荐答案

首先创建一个scnassets文件夹(不是必需但有用的)


  1. 在桌面上创建一个文件夹并将其扩展名为.scnassets

  1. Create a folder on your desktop and give it an extension of ".scnassets"

将你的collada(.dae)文件与你将在其中使用的任何纹理放在一起。

Put your collada(.dae) file along with any textures you will be using in it.

将文件夹拖到项目中并像往常一样保存为副本。

Drag the folder into your project and save as copy like usual.

点击你的scnassets文件夹,你会看到一个复选框(如果没有检查)转换为y向上轴。

Click on your scnassets folder and you will see a checked box (if not check it) for converting to a "y" up axis.

为场景模型指定纹理


  1. 在xcode中单击项目内的collada(.dae)文件。

  1. Click on your collada(.dae) file inside your project in xcode.

您应该看到您的场景,左侧是相机,灯光,材料等的列表。这是你的场景树。

You should see your scene and on its left side a list of cameras, lights, materials, and such. This is your scene tree.

打开材料选项卡,然后单击您的某个材料。

Open the materials tab and click on one of your materials.

在检查窗口的右侧,单击蓝色球形图标(材料检查器)以查看其中的漫反射,镜面反射等材料。

On the right hand side in the inspection window click on the blue ball shaped icon(Material inspector) to view the diffuse, specularity, and such of that one material.

单击漫反射选项卡,当它打开时,您应该在项目中选择颜色和纹理。在3d程序中选择模型上使用的纹理。只要您在3D程序中正确地展开UV,它们就应该立即应用于场景视图中。

Click on the diffuse tab and when it opens you should have an option of colors and your textures within your project. Select the texture you used on your model within 3d program. As long as you UV unwrapped them properly in your 3D program, they should apply instantly within your scene view.

如果我想在加载场景后更改我的素材怎么办?很高兴你问过!

为此,我们必须使用SCNSceneSource类的entryWithIdentifier方法。我将在这里使用swift因为它太棒了!在这里,我们去...

To do this we must use entryWithIdentifier method of SCNSceneSource class. I am going to use swift here because it is awesome! Here we go...


  1. 获取场景的网址(.dae),如此......

  1. Get the url of your scene(.dae) like so...

let url = NSBundle.mainBundle().URLForResource("YourFolder.scnassets/yourScene", withExtension "dae")


  • 现在让我们使用该网址...

  • Now lets put that url to use...

    let source = SCNSceneSource(URL: url, options: nil)
    


  • 单击你的.dae,在Scene Graph下面是项目列表,其中一项是你的几何。它的右边会有一个发球水壶,表示如此。我们将在这里使用它的名字。假设您的几何图形名称为Geo。像这样使用...

  • Click on your .dae and under Scene Graph is list of items one of which is your geometry. It will have a tee kettle just to the right of it signifying so. We are going to use its name here. Let say your geometry's name is Geo. Use it like so...

    let yourGeometry = source.entryWithIdentifier("Geo", withClass: SCNGeometry.self) as SCNGeometry
    


  • 现在我们有一个源连接到名为yourGeomerty的SCNNode。让我们创建一个像UIColor这样的新材料......

  • Now we have a source attatched to a SCNNode called yourGeomerty. Lets create a new material with a UIColor like so...

    let newMaterial = SCNMaterial()
    newMaterial.diffuse.contents = UIColor.redColor()
    


  • 最后我们将切换旧材料像这样的newMaterial ...

  • Finally we will switch out the old material with the newMaterial like so...

    yourGeometry.geometry.replaceMaterialAtIndex(0, withMaterial: newMaterial)
    


  • 如果您有多种材料,请使用它和其他索引。您还可以使用UIImage类来使用其他纹理而不是颜色。

    Play around with it and other indexes if you have more than one material. You can also use the UIImage class to use another texture instead of a color.

    提示
    如果要添加或删除scnassets文件夹中的内容,请导航到项目文件夹以执行此操作,不是xcode。我花了一段时间才弄明白,以为我会为每个人省去麻烦。

    TIP If you want to add to or delete something from your scnassets folder, navigate to your project folder to do so and not xcode. This took me a while to figure out so thought I would save everyone the trouble.

    这篇关于从Blender导出到COLLADA / .dae格式时包含纹理,以便在SceneKit中使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆