2010年6月3日木曜日

Collada攻略戦01

今日からColladadomによるdaeファイルの読み込みをやっていこうと思う。Colladadomのビルドについては今回は割愛。

参考にさせていただいたのは、hyper_jaianismさんの記事COLLADA DOM を使うです。
まずはファイルを開くための最短コード。

01#include <iostream>
02#include <dae.h>
03 
04int main()
05{
06   DAE dae;
07 
08   if(dae.load("./cube.dae") == DAE_OK)
09      std::cout << "File opened." << std::endl;
10   else
11      std::cout << "Couldn't open the file." << std::endl;
12 
13   dae.cleanup();
14   DAE::cleanup();
15 
16   return 0;
17}
実行して"File opened."と表示されればとりあえず成功だと思います。
TODO:
  • 頂点座標・法線・UV座標を読み込む
  • テクスチャ名を読み込む
読み込むファイルは立方体。Blenderがcollada形式で出力できるので使ってみるといいかもです。テキストデータですから、下記にも貼り付けておきます。メモ帳などにコピペして保存すればオッケーかと。念のためエンコードはUTF-8に変更してみてください。
001<?xml version="1.0" encoding="utf-8"?>
002<COLLADA version="1.4.0" xmlns="http://www.collada.org/2005/11/COLLADASchema">
003 <asset>
004  <contributor>
005   <author>Illusoft Collada 1.4.0 plugin for Blender - http://colladablender.illusoft.com</author>
006   <authoring_tool>Blender v:249 - Illusoft Collada Exporter v:0.3.162</authoring_tool>
007   <comments></comments>
008   <copyright></copyright>
009   <source_data>file://C://</source_data>
010  </contributor>
011  <created>2010-05-13T15:39:45.625000</created>
012  <modified>2010-05-13T15:39:45.625000</modified>
013  <unit meter="0.01" name="centimeter"/>
014  <up_axis>Z_UP</up_axis>
015 </asset>
016 <library_cameras>
017  <camera id="Camera-Camera" name="Camera-Camera">
018   <optics>
019    <technique_common>
020     <perspective>
021      <yfov>49.13434</yfov>
022      <znear>0.1</znear>
023      <zfar>100.0</zfar>
024     </perspective>
025    </technique_common>
026   </optics>
027  </camera>
028 </library_cameras>
029 <library_effects>
030  <effect id="Material-fx" name="Material-fx">
031   <profile_COMMON>
032    <technique sid="blender">
033     <phong>
034      <emission>
035       <color>0.00000 0.00000 0.00000 1</color>
036      </emission>
037      <ambient>
038       <color>0.40000 0.40000 0.40000 1</color>
039      </ambient>
040      <diffuse>
041       <color>0.80000 0.80000 0.80000 1</color>
042      </diffuse>
043      <specular>
044       <color>0.50000 0.50000 0.50000 1</color>
045      </specular>
046      <shininess>
047       <float>12.5</float>
048      </shininess>
049      <reflective>
050       <color>1.00000 1.00000 1.00000 1</color>
051      </reflective>
052      <reflectivity>
053       <float>0.0</float>
054      </reflectivity>
055      <transparent>
056       <color>1 1 1 1</color>
057      </transparent>
058      <transparency>
059       <float>1.0</float>
060      </transparency>
061     </phong>
062    </technique>
063   </profile_COMMON>
064  </effect>
065 </library_effects>
066 <library_lights>
067  <light id="Spot" name="Spot">
068   <technique_common>
069    <point>
070     <color>1.00000 1.00000 1.00000</color>
071     <constant_attenuation>1.0</constant_attenuation>
072     <linear_attenuation>0.0</linear_attenuation>
073     <quadratic_attenuation>0.0</quadratic_attenuation>
074    </point>
075   </technique_common>
076  </light>
077 </library_lights>
078 <library_materials>
079  <material id="Material" name="Material">
080   <instance_effect url="#Material-fx"/>
081  </material>
082 </library_materials>
083 <library_geometries>
084  <geometry id="Cube_001" name="Cube_001">
085   <mesh>
086    <source id="Cube_001-Position">
087     <float_array count="24" id="Cube_001-Position-array">1.00000 1.00000 -1.00000 1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 1.00000 -1.00000 1.00000 1.00000 1.00000 1.00000 -1.00000 1.00000 -1.00000 -1.00000 1.00000 -1.00000 1.00000 1.00000</float_array>
088     <technique_common>
089      <accessor count="8" source="#Cube_001-Position-array" stride="3">
090       <param type="float" name="X"></param>
091       <param type="float" name="Y"></param>
092       <param type="float" name="Z"></param>
093      </accessor>
094     </technique_common>
095    </source>
096    <source id="Cube_001-Normals">
097     <float_array count="18" id="Cube_001-Normals-array">0.00000 0.00000 -1.00000 0.00000 -0.00000 1.00000 1.00000 -0.00000 0.00000 -0.00000 -1.00000 -0.00000 -1.00000 0.00000 -0.00000 0.00000 1.00000 0.00000</float_array>
098     <technique_common>
099      <accessor count="6" source="#Cube_001-Normals-array" stride="3">
100       <param type="float" name="X"></param>
101       <param type="float" name="Y"></param>
102       <param type="float" name="Z"></param>
103      </accessor>
104     </technique_common>
105    </source>
106    <vertices id="Cube_001-Vertex">
107     <input semantic="POSITION" source="#Cube_001-Position"/>
108    </vertices>
109    <triangles count="12" material="Material">
110     <input offset="0" semantic="VERTEX" source="#Cube_001-Vertex"/>
111     <input offset="1" semantic="NORMAL" source="#Cube_001-Normals"/>
112     <p>0 0 1 0 2 0 2 0 3 0 0 0 4 1 7 1 6 1 6 1 5 1 4 1 0 2 4 2 5 2 5 2 1 2 0 2 1 3 5 3 6 3 6 3 2 3 1 3 2 4 6 4 7 4 7 4 3 4 2 4 4 5 0 5 3 5 3 5 7 5 4 5</p>
113    </triangles>
114   </mesh>
115  </geometry>
116 </library_geometries>
117 <library_visual_scenes>
118  <visual_scene id="Scene" name="Scene">
119   <node layer="L1" id="Cube" name="Cube">
120    <translate sid="translate">0.00000 0.00000 0.00000</translate>
121    <rotate sid="rotateZ">0 0 1 0.00000</rotate>
122    <rotate sid="rotateY">0 1 0 -0.00000</rotate>
123    <rotate sid="rotateX">1 0 0 0.00000</rotate>
124    <scale sid="scale">1.00000 1.00000 1.00000</scale>
125    <instance_geometry url="#Cube_001">
126     <bind_material>
127      <technique_common>
128       <instance_material symbol="Material" target="#Material">
129        <bind_vertex_input input_semantic="TEXCOORD" input_set="1" semantic="CHANNEL1"/>
130       </instance_material>
131      </technique_common>
132     </bind_material>
133    </instance_geometry>
134   </node>
135   <node layer="L1" id="Lamp" name="Lamp">
136    <translate sid="translate">4.07625 1.00545 5.90386</translate>
137    <rotate sid="rotateZ">0 0 1 106.93632</rotate>
138    <rotate sid="rotateY">0 1 0 3.16371</rotate>
139    <rotate sid="rotateX">1 0 0 37.26105</rotate>
140    <scale sid="scale">1.00000 1.00000 1.00000</scale>
141    <instance_light url="#Spot"/>
142   </node>
143   <node layer="L1" id="Camera" name="Camera">
144    <translate sid="translate">7.48113 -6.50764 5.34367</translate>
145    <rotate sid="rotateZ">0 0 1 46.69194</rotate>
146    <rotate sid="rotateY">0 1 0 0.61977</rotate>
147    <rotate sid="rotateX">1 0 0 63.55930</rotate>
148    <scale sid="scale">1.00000 1.00000 1.00000</scale>
149    <instance_camera url="#Camera-Camera"/>
150   </node>
151  </visual_scene>
152 </library_visual_scenes>
153 <library_physics_materials>
154  <physics_material id="Cube-PhysicsMaterial" name="Cube-PhysicsMaterial">
155   <technique_common>
156    <dynamic_friction>0.5</dynamic_friction>
157    <restitution>0.0</restitution>
158    <static_friction>0.5</static_friction>
159   </technique_common>
160  </physics_material>
161 </library_physics_materials>
162 <library_physics_models>
163  <physics_model id="Scene-PhysicsModel" name="Scene-PhysicsModel">
164   <rigid_body name="Cube-RigidBody" sid="Cube-RigidBody">
165    <technique_common>
166     <dynamic>false</dynamic>
167     <mass>0</mass>
168     <instance_physics_material url="#Cube-PhysicsMaterial"/>
169     <shape>
170      <instance_geometry url="#Cube_001"/>
171     </shape>
172    </technique_common>
173   </rigid_body>
174  </physics_model>
175 </library_physics_models>
176 <library_physics_scenes>
177  <physics_scene id="Scene-Physics" name="Scene-Physics">
178   <instance_physics_model url="#Scene-PhysicsModel">
179    <instance_rigid_body body="Cube-RigidBody" target="#Cube"/>
180   </instance_physics_model>
181  </physics_scene>
182 </library_physics_scenes>
183 <scene>
184  <instance_physics_scene url="#Scene-Physics"/>
185  <instance_visual_scene url="#Scene"/>
186 </scene>
187</COLLADA>

0 件のコメント:

コメントを投稿