PageRenderTime 37ms CodeModel.GetById 23ms app.highlight 12ms RepoModel.GetById 0ms app.codeStats 0ms

/src/Assets_Converter/AssimpSceneData.cpp

http://github.com/Akranar/daguerreo
C++ | 136 lines | 112 code | 24 blank | 0 comment | 8 complexity | fd6473d8369b0b751124c9c017eed962 MD5 | raw file
Possible License(s): AGPL-3.0, LGPL-2.1, LGPL-3.0, GPL-2.0
  1#include "AssimpSceneData.h"
  2#include "ExLib_BinaryFileStream.h"
  3#include <sstream>
  4
  5#include "ExLib_SceneBase.h"
  6#include "ExLib_BoundingVolume.h"
  7
  8AssimpSceneData::AssimpSceneData()
  9{
 10
 11}
 12AssimpSceneData::~AssimpSceneData()
 13{
 14	
 15	for (unsigned int i = 0; i < skeletons.size(); ++i)
 16	{
 17		delete skeletons[i];
 18	}
 19	skeletons.clear();
 20	for (unsigned int i = 0; i < skeletal_animations.size(); ++i)
 21	{
 22		delete skeletal_animations[i];
 23	}
 24	skeletal_animations.clear();
 25	
 26}
 27
 28void AssimpSceneData::OutputMeshResources(const std::string & filename)
 29{
 30	BinaryFileStream stream;
 31	for (unsigned int i = 0; i < mesh_descs.GetSize(); ++i)
 32	{
 33		RendererBaseMesh & current_mesh = mesh_descs[i];
 34		std::stringstream string_stream;
 35		string_stream << filename << '_' << i << '.';
 36
 37		{
 38			std::stringstream out_file;
 39			out_file << string_stream.str() << "vbr";
 40
 41			STLSerializer<FixedArray<unsigned char> > data_serializer(stream);
 42			stream.StartWrite(out_file.str().c_str());
 43			{
 44				stream.Save(current_mesh.GetFormatDesc());
 45				stream.Save(current_mesh.GetVertexDesc());
 46				data_serializer.Save(current_mesh.GetVertexData());
 47			}
 48			stream.Close();
 49
 50		}
 51
 52		{
 53			std::stringstream out_file;
 54			out_file << string_stream.str() << "ibr";
 55
 56			STLSerializer<FixedArray<unsigned char> > data_serializer(stream);
 57			stream.StartWrite(out_file.str().c_str());
 58			{
 59				stream.Save(current_mesh.GetIndexDesc());
 60				data_serializer.Save(current_mesh.GetIndexData());
 61			}
 62			stream.Close();
 63
 64		}
 65	}
 66}
 67void AssimpSceneData::OutputSceneGraphResources(const std::string & filename)
 68{
 69	BinaryFileStream stream;
 70
 71	for (unsigned int i = 0; i < mesh_descs.GetSize(); ++i)
 72	{
 73		RendererBaseMesh & current_mesh = mesh_descs[i];
 74		std::stringstream string_stream;
 75		string_stream << filename << '_' << i << '.';
 76
 77		std::stringstream vb_file;
 78		vb_file << string_stream.str() << "vbr";
 79		std::stringstream ib_file;
 80		ib_file << string_stream.str() << "ibr";
 81		std::stringstream out_file;
 82		out_file << string_stream.str() << "vsr";
 83
 84		DescVisual visual_desc;
 85		visual_desc.SetVertexBufferID(vb_file.str());
 86		visual_desc.SetIndexBufferID(ib_file.str());
 87
 88		
 89		DescVertexFormatEntry & attrib = current_mesh.GetFormatDesc()[0];
 90		if (attrib.GetName().compare("POSITION") == 0)
 91		{//Only AABB supported currently.
 92			visual_desc.CreateBoundingVolume(BoundingVolume::BV_AABB, 
 93				current_mesh.GetVertexData().GetData() + attrib.GetOffset(), 
 94				attrib.GetStride() / 4,  //NEED TO FIX THIS LATER
 95				current_mesh.GetVertexData().GetSize() / attrib.GetStride());
 96		}
 97
 98		stream.StartWrite(out_file.str().c_str());
 99		stream.Save(visual_desc);
100		stream.Close();
101	}
102}
103void AssimpSceneData::OuptutAnimationResources(const std::string & filename)
104{
105	BinaryFileStream stream;
106
107	for (unsigned int i = 0; i < skeletons.size(); ++i)
108	{
109		std::stringstream string_stream;
110		string_stream << filename << '_' << i << '.';
111
112		std::stringstream skeleton_file;
113		skeleton_file << string_stream.str() << "skel";
114
115		stream.StartWrite(skeleton_file.str().c_str());
116		{
117			stream.Save(skeletons[i]);
118		}
119		stream.Close();
120	}
121
122	for (unsigned int i = 0; i < skeletal_animations.size(); ++i)
123	{
124		std::stringstream string_stream;
125		string_stream << filename << '_' << i << '.';
126
127		std::stringstream anim_file;
128		anim_file << string_stream.str() << "anim";
129
130		stream.StartWrite(anim_file.str().c_str());
131		{
132			stream.Save(skeletal_animations[i]);
133		}
134		stream.Close();
135	}
136}