【发布时间】:2016-09-27 17:16:45
【问题描述】:
根据WWDC 2013 What's new in SceneKit,变形器的目标几何形状可以包含在 .dae 文件中:
所有变形信息和动画都可以从 DAE 文件中加载,或者您可以通过编程方式创建所有内容。”
我有一个包含变形控制器的 collada .dae 文件。该文件由 Blender 的 Collada 导出器创建,并选择了“包含形状键”。这会将 Blender 的形状键转换为 Collada 的变形控制器。当我检查生成的文件时,我可以看到<library_geometries> 中主要几何图形后面列出的形状键。标题如下所示:
<geometry id="Octopus-mesh_morph_Rest" name="Rest">
<mesh>
<source id="Octopus-mesh_morph_Rest-positions">
其中Rest 是形状键的名称。形状键/变形目标的几何形状随后跟随此标题。
定义完所有几何图形后,就有了<library_controllers>:
<library_controllers>
<controller id="Octopus-morph" name="Octopus-morph">
<morph source="#Octopus-mesh" method="NORMALIZED">
<source id="Octopus-targets">
<IDREF_array id="Octopus-targets-array" count="1">Octopus-mesh_morph_Rest</IDREF_array>
<technique_common>
<accessor source="#Octopus-targets-array" count="1" stride="1">
<param name="IDREF" type="IDREF"/>
</accessor>
</technique_common>
</source>
<source id="Octopus-weights">
<float_array id="Octopus-weights-array" count="1">0</float_array>
<technique_common>
<accessor source="#Octopus-weights-array" count="1" stride="1">
<param name="MORPH_WEIGHT" type="float"/>
</accessor>
</technique_common>
</source>
<targets>
<input semantic="MORPH_TARGET" source="#Octopus-targets"/>
<input semantic="MORPH_WEIGHT" source="#Octopus-weights"/>
</targets>
</morph>
</controller>
</library_controllers>
如何从 SceneKit 中访问这些变形控制器?在 Xcode 场景编辑器中,没有任何迹象表明变形控制器已被识别,例如按下播放键什么都不做,动画文件夹为空,除了基本几何图形之外没有其他几何图形。
当我加载节点时,它没有附加morpher 属性,也没有动画键。我尝试在树中搜索名为“Rest”的条目,但没有任何内容。
let collada = SCNScene(named: "octopus.dae", inDirectory: "art.scnassets", options: nil)
let octopus = collada?.rootNode.childNodeWithName("Octopus", recursively: true)
octopus?.position = SCNVector3(0,-2,0)
print(octopus?.morpher?.animationKeys) //nil
print(octopus?.animationKeys) //Optional([])
有没有人设法从 Collada .dae 文件的变形控制器加载 SCNMorpher 目标? Blender .dae 导出器可能有问题吗? Objective-C 的答案以及 Swift 的欢迎。谢谢。
编辑
我还尝试使用NSBundle 加载.dae,并将.dae 放在art.scnassets 文件夹的内部和外部,看看是否有区别,但仍然没有骰子:
let collada = NSBundle.mainBundle().URLForResource("octopus", withExtension: "dae")!
let sceneSource = SCNSceneSource(URL: collada, options: [
SCNSceneSourceAnimationImportPolicyKey : SCNSceneSourceAnimationImportPolicyDoNotPlay
])
let octopusDae = sceneSource?.entryWithIdentifier("Octopus", withClass: SCNNode.self)
//let deform = sceneSource?.entryWithIdentifier("Rest", withClass: SCNGeometry.self)
print(sceneSource?.entriesPassingTest(){(entry, id, stop) in return id.containsString("Rest") })
print(octopusDae!.morpher)
print(octopusDae!.animationKeys)
编辑 2
通过将每个 shape-key 保存为单独的 .obj 文件,我已经成功地使用了 .obj 文件。但我真的很想让它与 Blender 的 .dae 文件一起使用,因为它可以使迭代开发和使用具有大量形状键的模型更容易(另外,在 SceneKit 中使用 Blender .obj 文件有一些奇怪的怪癖,例如所有纹理坐标似乎都垂直翻转)。我需要的所有几何图形都在 .dae 文件中。我只是无法让 SceneKit 看到它。
【问题讨论】:
标签: animation blender scenekit collada