#include <iostream>
#include <list>
#include <assimp/version.h>
#include <assimp/scene.h>
#include <assimp/postprocess.h>
#include <assimp/Importer.hpp>
#include <assimp/IOStream.hpp>
#include <assimp/IOSystem.hpp>
int main(int argc, char *argv[])
{
	int i;
	Assimp::Importer importer;
	uint32_t flags = aiProcessPreset_TargetRealtime_Fast | aiProcess_TransformUVCoords | aiProcess_FlipUVs;
	flags &= ~(aiProcess_JoinIdenticalVertices | aiProcess_CalcTangentSpace); // optimize for fast loading
	if((flags & (aiProcess_GenSmoothNormals | aiProcess_GenNormals)) != aiProcess_GenNormals)
		flags &= ~aiProcess_GenNormals; // prefer smooth normals

	float maxEdgeAngle = 0.75f;

	importer.SetPropertyFloat("PP_GSN_MAX_SMOOTHING_ANGLE", maxEdgeAngle);
	importer.SetPropertyBool(AI_CONFIG_IMPORT_FBX_EMBEDDED_TEXTURES_LEGACY_NAMING, true);
	
	if (argc < 2) {
		std::cerr << "path name needed" << std::endl;
		return 1;
	}
	const char *pname = argv[1];
	const aiScene* scene = importer.ReadFile(pname,
			flags);
	std::list<aiNode *> queue;
	if (!scene) {
		std::cerr << "could not process file" << std::endl;
		return 1;
	}
	queue.push_back(scene->mRootNode);
	while(!queue.empty()) {
		aiNode *node = queue.front();
		queue.pop_front();
		for (i = 0; i < node->mNumMeshes; i++) {
			aiMesh* mesh = scene->mMeshes[node->mMeshes[i]];
			int uv_count = 0;
			for (int uvindex = 0; uvindex < AI_MAX_NUMBER_OF_TEXTURECOORDS; uvindex++) {
				aiVector3D* uv = mesh->mTextureCoords[uvindex];
				if (!uv)
					break;
				uv_count++;
			}
			std::cout << "node: " << node->mName.C_Str() << " mesh: " << i << " mesh uv count: " << uv_count << std::endl;
		}
		for (i = 0; i < node->mNumChildren; i++)
			queue.push_back(node->mChildren[i]);
	}
	return 0;
}
