2016-09-11 10 views
0

モーフィングターゲットの配列を作成し、ベースジオメトリからターゲットジオメトリにメッシュをアニメートするには、COLLADAファイルの<geometry>を読む必要があります。SceneKitでCOLLADA(.dae)ファイルからジオメトリを取得する方法

私は(COLLADAファイルは一つだけ<node>を持っている)ノードに埋め込まれていますベースジオメトリからジオメトリにアクセスすることができます。

planeNode.geometry = scene!.rootNode.childNodeWithName("Plane", recursively: true)!.geometry 

ここでCOLLADAファイルの完全なソースコードがあります(3つのジオメトリを持っており、 1つのノードだけ)1つのジオメトリへのアクセスを得る:

<?xml version="1.0" encoding="utf-8"?> 
<COLLADA xmlns="http://www.collada.org/2005/11/COLLADASchema" version="1.4.1"> 
    <asset> 
    <contributor> 
     <author>Blender User</author> 
     <authoring_tool>Blender 2.77.0 commit date:2016-04-05, commit time:18:12, hash:abf6f08</authoring_tool> 
    </contributor> 
    <unit name="meter" meter="1"/> 
    <up_axis>Z_UP</up_axis> 
    </asset> 
    <library_images/> 
    <library_geometries> 
    <geometry id="Plane-mesh" name="Plane"> 
     <mesh> 
     <source id="Plane-mesh-positions"> 
      <float_array id="Plane-mesh-positions-array" count="12">-1 -1 0 1 -1 0 -1 1 0 1 1 0</float_array> 
      <technique_common> 
      <accessor source="#Plane-mesh-positions-array" count="4" stride="3"> 
       <param name="X" type="float"/> 
       <param name="Y" type="float"/> 
       <param name="Z" type="float"/> 
      </accessor> 
      </technique_common> 
     </source> 
     <source id="Plane-mesh-normals"> 
      <float_array id="Plane-mesh-normals-array" count="3">0 0 1</float_array> 
      <technique_common> 
      <accessor source="#Plane-mesh-normals-array" count="1" stride="3"> 
       <param name="X" type="float"/> 
       <param name="Y" type="float"/> 
       <param name="Z" type="float"/> 
      </accessor> 
      </technique_common> 
     </source> 
     <vertices id="Plane-mesh-vertices"> 
      <input semantic="POSITION" source="#Plane-mesh-positions"/> 
     </vertices> 
     <polylist count="2"> 
      <input semantic="VERTEX" source="#Plane-mesh-vertices" offset="0"/> 
      <input semantic="NORMAL" source="#Plane-mesh-normals" offset="1"/> 
      <vcount>3 3 </vcount> 
      <p>1 0 2 0 0 0 1 0 3 0 2 0</p> 
     </polylist> 
     </mesh> 
    </geometry> 
    <geometry id="Plane-mesh_morph_Key1" name="Key1"> 
     <mesh> 
     <source id="Plane-mesh_morph_Key1-positions"> 
      <float_array id="Plane-mesh_morph_Key1-positions-array" count="12">-1 -1 0 1 -1 0 -1 1 0 1 2 0</float_array> 
      <technique_common> 
      <accessor source="#Plane-mesh_morph_Key1-positions-array" count="4" stride="3"> 
       <param name="X" type="float"/> 
       <param name="Y" type="float"/> 
       <param name="Z" type="float"/> 
      </accessor> 
      </technique_common> 
     </source> 
     <source id="Plane-mesh_morph_Key1-normals"> 
      <float_array id="Plane-mesh_morph_Key1-normals-array" count="6">0 0 1 0 0 1</float_array> 
      <technique_common> 
      <accessor source="#Plane-mesh_morph_Key1-normals-array" count="2" stride="3"> 
       <param name="X" type="float"/> 
       <param name="Y" type="float"/> 
       <param name="Z" type="float"/> 
      </accessor> 
      </technique_common> 
     </source> 
     <vertices id="Plane-mesh_morph_Key1-vertices"> 
      <input semantic="POSITION" source="#Plane-mesh_morph_Key1-positions"/> 
     </vertices> 
     <polylist count="2"> 
      <input semantic="VERTEX" source="#Plane-mesh_morph_Key1-vertices" offset="0"/> 
      <input semantic="NORMAL" source="#Plane-mesh_morph_Key1-normals" offset="1"/> 
      <vcount>3 3 </vcount> 
      <p>1 0 2 0 0 0 1 1 3 1 2 1</p> 
     </polylist> 
     </mesh> 
    </geometry> 
    <geometry id="Plane-mesh_morph_Key2" name="Key2"> 
     <mesh> 
     <source id="Plane-mesh_morph_Key2-positions"> 
      <float_array id="Plane-mesh_morph_Key2-positions-array" count="12">-1 -1 0 1 -1 0 -1 1 0 2 1 0</float_array> 
      <technique_common> 
      <accessor source="#Plane-mesh_morph_Key2-positions-array" count="4" stride="3"> 
       <param name="X" type="float"/> 
       <param name="Y" type="float"/> 
       <param name="Z" type="float"/> 
      </accessor> 
      </technique_common> 
     </source> 
     <source id="Plane-mesh_morph_Key2-normals"> 
      <float_array id="Plane-mesh_morph_Key2-normals-array" count="3">0 0 1</float_array> 
      <technique_common> 
      <accessor source="#Plane-mesh_morph_Key2-normals-array" count="1" stride="3"> 
       <param name="X" type="float"/> 
       <param name="Y" type="float"/> 
       <param name="Z" type="float"/> 
      </accessor> 
      </technique_common> 
     </source> 
     <vertices id="Plane-mesh_morph_Key2-vertices"> 
      <input semantic="POSITION" source="#Plane-mesh_morph_Key2-positions"/> 
     </vertices> 
     <polylist count="2"> 
      <input semantic="VERTEX" source="#Plane-mesh_morph_Key2-vertices" offset="0"/> 
      <input semantic="NORMAL" source="#Plane-mesh_morph_Key2-normals" offset="1"/> 
      <vcount>3 3 </vcount> 
      <p>1 0 2 0 0 0 1 0 3 0 2 0</p> 
     </polylist> 
     </mesh> 
    </geometry> 
    </library_geometries> 
    <library_controllers> 
    <controller id="Plane-morph" name="Plane-morph"> 
     <morph source="#Plane-mesh" method="NORMALIZED"> 
     <source id="Plane-targets"> 
      <IDREF_array id="Plane-targets-array" count="2">Plane-mesh_morph_Key1 Plane-mesh_morph_Key2</IDREF_array> 
      <technique_common> 
      <accessor source="#Plane-targets-array" count="2" stride="1"> 
       <param name="IDREF" type="IDREF"/> 
      </accessor> 
      </technique_common> 
     </source> 
     <source id="Plane-weights"> 
      <float_array id="Plane-weights-array" count="2">0 0</float_array> 
      <technique_common> 
      <accessor source="#Plane-weights-array" count="2" stride="1"> 
       <param name="MORPH_WEIGHT" type="float"/> 
      </accessor> 
      </technique_common> 
     </source> 
     <targets> 
      <input semantic="MORPH_TARGET" source="#Plane-targets"/> 
      <input semantic="MORPH_WEIGHT" source="#Plane-weights"/> 
     </targets> 
     </morph> 
    </controller> 
    </library_controllers> 
    <library_visual_scenes> 
    <visual_scene id="Scene" name="Scene"> 
     <node id="Plane" name="Plane" type="NODE"> 
     <matrix sid="transform">1 0 0 0 0 -4.37114e-8 -1 0 0 1 -4.37114e-8 0 0 0 0 1</matrix> 
     <instance_geometry url="#Plane-mesh" name="Plane"/> 
     </node> 
    </visual_scene> 
    </library_visual_scenes> 
    <scene> 
    <instance_visual_scene url="#Scene"/> 
    </scene> 
</COLLADA> 

すべてのヘルプは大歓迎です。ありがとう!

+0

残念ながら、SceneKitはジオメトリタグを読み取っていないので、ジオメトリを関連付けたノードを作成して非表示にする必要があります。最高のものではなく、より良い方法の欠如のために働いた。ここに作業コード:[リンク](https://forums.developer.apple.com/message/178847#178847) – Joao

答えて

0

entryWithIdentifier:withClass:を使用すると、シーングラフにないオブジェクトを取得できます。また、オーサリングツールでノードにモーファーを付けて、ノードのmorpherプロパティを使用してターゲットジオメトリを取得することもできます。

+0

ありがとう@mnuages。コードで2番目のオプションを理解するのを手伝ってもらえますか? – Joao

+0

私は最初のオプションを試してみましたが、まだ一つだけのジオメトリ 'FUNC loadGeometriesFromSceneSource(sceneSource:SCNSceneSource)へのアクセスを取得しました識別子で識別のための[文字列] として{ LET識別子= sceneSource.identifiersOfEntriesWithClass(SCNGeometry.selfを) { プリント(識別子)//それは私だけベースジオメトリ morphs.append(!sceneSource.entryWithIdentifier(識別子、withClass:SCNGeometry.self))を取得します }? } ' 私が間違って何をやっているの... 。 – Joao

関連する問題