参考にさせていただいたのは、hyper_jaianismさんの記事COLLADA DOM を使うです。
まずはファイルを開くための最短コード。
#include <iostream> #include <dae.h> int main() { DAE dae; if(dae.load("./cube.dae") == DAE_OK) std::cout << "File opened." << std::endl; else std::cout << "Couldn't open the file." << std::endl; dae.cleanup(); DAE::cleanup(); return 0; }実行して"File opened."と表示されればとりあえず成功だと思います。
TODO:
- 頂点座標・法線・UV座標を読み込む
- テクスチャ名を読み込む
<?xml version="1.0" encoding="utf-8"?> <COLLADA version="1.4.0" xmlns="http://www.collada.org/2005/11/COLLADASchema"> <asset> <contributor> <author>Illusoft Collada 1.4.0 plugin for Blender - http://colladablender.illusoft.com</author> <authoring_tool>Blender v:249 - Illusoft Collada Exporter v:0.3.162</authoring_tool> <comments></comments> <copyright></copyright> <source_data>file://C://</source_data> </contributor> <created>2010-05-13T15:39:45.625000</created> <modified>2010-05-13T15:39:45.625000</modified> <unit meter="0.01" name="centimeter"/> <up_axis>Z_UP</up_axis> </asset> <library_cameras> <camera id="Camera-Camera" name="Camera-Camera"> <optics> <technique_common> <perspective> <yfov>49.13434</yfov> <znear>0.1</znear> <zfar>100.0</zfar> </perspective> </technique_common> </optics> </camera> </library_cameras> <library_effects> <effect id="Material-fx" name="Material-fx"> <profile_COMMON> <technique sid="blender"> <phong> <emission> <color>0.00000 0.00000 0.00000 1</color> </emission> <ambient> <color>0.40000 0.40000 0.40000 1</color> </ambient> <diffuse> <color>0.80000 0.80000 0.80000 1</color> </diffuse> <specular> <color>0.50000 0.50000 0.50000 1</color> </specular> <shininess> <float>12.5</float> </shininess> <reflective> <color>1.00000 1.00000 1.00000 1</color> </reflective> <reflectivity> <float>0.0</float> </reflectivity> <transparent> <color>1 1 1 1</color> </transparent> <transparency> <float>1.0</float> </transparency> </phong> </technique> </profile_COMMON> </effect> </library_effects> <library_lights> <light id="Spot" name="Spot"> <technique_common> <point> <color>1.00000 1.00000 1.00000</color> <constant_attenuation>1.0</constant_attenuation> <linear_attenuation>0.0</linear_attenuation> <quadratic_attenuation>0.0</quadratic_attenuation> </point> </technique_common> </light> </library_lights> <library_materials> <material id="Material" name="Material"> <instance_effect url="#Material-fx"/> </material> </library_materials> <library_geometries> <geometry id="Cube_001" name="Cube_001"> <mesh> <source id="Cube_001-Position"> <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> <technique_common> <accessor count="8" source="#Cube_001-Position-array" stride="3"> <param type="float" name="X"></param> <param type="float" name="Y"></param> <param type="float" name="Z"></param> </accessor> </technique_common> </source> <source id="Cube_001-Normals"> <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> <technique_common> <accessor count="6" source="#Cube_001-Normals-array" stride="3"> <param type="float" name="X"></param> <param type="float" name="Y"></param> <param type="float" name="Z"></param> </accessor> </technique_common> </source> <vertices id="Cube_001-Vertex"> <input semantic="POSITION" source="#Cube_001-Position"/> </vertices> <triangles count="12" material="Material"> <input offset="0" semantic="VERTEX" source="#Cube_001-Vertex"/> <input offset="1" semantic="NORMAL" source="#Cube_001-Normals"/> <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> </triangles> </mesh> </geometry> </library_geometries> <library_visual_scenes> <visual_scene id="Scene" name="Scene"> <node layer="L1" id="Cube" name="Cube"> <translate sid="translate">0.00000 0.00000 0.00000</translate> <rotate sid="rotateZ">0 0 1 0.00000</rotate> <rotate sid="rotateY">0 1 0 -0.00000</rotate> <rotate sid="rotateX">1 0 0 0.00000</rotate> <scale sid="scale">1.00000 1.00000 1.00000</scale> <instance_geometry url="#Cube_001"> <bind_material> <technique_common> <instance_material symbol="Material" target="#Material"> <bind_vertex_input input_semantic="TEXCOORD" input_set="1" semantic="CHANNEL1"/> </instance_material> </technique_common> </bind_material> </instance_geometry> </node> <node layer="L1" id="Lamp" name="Lamp"> <translate sid="translate">4.07625 1.00545 5.90386</translate> <rotate sid="rotateZ">0 0 1 106.93632</rotate> <rotate sid="rotateY">0 1 0 3.16371</rotate> <rotate sid="rotateX">1 0 0 37.26105</rotate> <scale sid="scale">1.00000 1.00000 1.00000</scale> <instance_light url="#Spot"/> </node> <node layer="L1" id="Camera" name="Camera"> <translate sid="translate">7.48113 -6.50764 5.34367</translate> <rotate sid="rotateZ">0 0 1 46.69194</rotate> <rotate sid="rotateY">0 1 0 0.61977</rotate> <rotate sid="rotateX">1 0 0 63.55930</rotate> <scale sid="scale">1.00000 1.00000 1.00000</scale> <instance_camera url="#Camera-Camera"/> </node> </visual_scene> </library_visual_scenes> <library_physics_materials> <physics_material id="Cube-PhysicsMaterial" name="Cube-PhysicsMaterial"> <technique_common> <dynamic_friction>0.5</dynamic_friction> <restitution>0.0</restitution> <static_friction>0.5</static_friction> </technique_common> </physics_material> </library_physics_materials> <library_physics_models> <physics_model id="Scene-PhysicsModel" name="Scene-PhysicsModel"> <rigid_body name="Cube-RigidBody" sid="Cube-RigidBody"> <technique_common> <dynamic>false</dynamic> <mass>0</mass> <instance_physics_material url="#Cube-PhysicsMaterial"/> <shape> <instance_geometry url="#Cube_001"/> </shape> </technique_common> </rigid_body> </physics_model> </library_physics_models> <library_physics_scenes> <physics_scene id="Scene-Physics" name="Scene-Physics"> <instance_physics_model url="#Scene-PhysicsModel"> <instance_rigid_body body="Cube-RigidBody" target="#Cube"/> </instance_physics_model> </physics_scene> </library_physics_scenes> <scene> <instance_physics_scene url="#Scene-Physics"/> <instance_visual_scene url="#Scene"/> </scene> </COLLADA>
0 件のコメント:
コメントを投稿