今日からColladadomによるdaeファイルの読み込みをやっていこうと思う。Colladadomのビルドについては今回は割愛。
参考にさせていただいたのは、
hyper_jaianismさんの記事
COLLADA DOM を使うです。
まずはファイルを開くための最短コード。
08 | if (dae.load( "./cube.dae" ) == DAE_OK) |
09 | std::cout << "File opened." << std::endl; |
11 | std::cout << "Couldn't open the file." << std::endl; |
実行して"File opened."と表示されればとりあえず成功だと思います。
TODO:
- 頂点座標・法線・UV座標を読み込む
- テクスチャ名を読み込む
読み込むファイルは立方体。Blenderがcollada形式で出力できるので使ってみるといいかもです。テキストデータですから、下記にも貼り付けておきます。メモ帳などにコピペして保存すればオッケーかと。念のためエンコードはUTF-8に変更してみてください。
001 | <? xml version = "1.0" encoding = "utf-8" ?> |
006 | < authoring_tool >Blender v:249 - Illusoft Collada Exporter v:0.3.162</ authoring_tool > |
007 | < comments ></ comments > |
008 | < copyright ></ copyright > |
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 > |
017 | < camera id = "Camera-Camera" name = "Camera-Camera" > |
021 | < yfov >49.13434</ yfov > |
030 | < effect id = "Material-fx" name = "Material-fx" > |
032 | < technique sid = "blender" > |
035 | < color >0.00000 0.00000 0.00000 1</ color > |
038 | < color >0.40000 0.40000 0.40000 1</ color > |
041 | < color >0.80000 0.80000 0.80000 1</ color > |
044 | < color >0.50000 0.50000 0.50000 1</ color > |
050 | < color >1.00000 1.00000 1.00000 1</ color > |
056 | < color >1 1 1 1</ color > |
067 | < light id = "Spot" name = "Spot" > |
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 > |
079 | < material id = "Material" name = "Material" > |
080 | < instance_effect url = "#Material-fx" /> |
084 | < geometry id = "Cube_001" name = "Cube_001" > |
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 > |
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 > |
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 > |
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 > |
106 | < vertices id = "Cube_001-Vertex" > |
107 | < input semantic = "POSITION" source = "#Cube_001-Position" /> |
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 > |
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" > |
128 | < instance_material symbol = "Material" target = "#Material" > |
129 | < bind_vertex_input input_semantic = "TEXCOORD" input_set = "1" semantic = "CHANNEL1" /> |
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" /> |
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" /> |
152 | </ library_visual_scenes > |
153 | < library_physics_materials > |
154 | < physics_material id = "Cube-PhysicsMaterial" name = "Cube-PhysicsMaterial" > |
156 | < dynamic_friction >0.5</ dynamic_friction > |
157 | < restitution >0.0</ restitution > |
158 | < static_friction >0.5</ static_friction > |
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" > |
166 | < dynamic >false</ dynamic > |
168 | < instance_physics_material url = "#Cube-PhysicsMaterial" /> |
170 | < instance_geometry url = "#Cube_001" /> |
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 > |
182 | </ library_physics_scenes > |
184 | < instance_physics_scene url = "#Scene-Physics" /> |
185 | < instance_visual_scene url = "#Scene" /> |
0 件のコメント:
コメントを投稿