
/***************************************************************************
*                                                                          *
*  Copyright (C) Golaem S.A.  All Rights Reserved.                         *
*                                                                          *
***************************************************************************/
#pragma once
#if defined(GLM_EXPORT_ALEMBIC)

#include <glmString.h>
#include <glmArray.h>
#include "glmMap.h"

#include "glmCrowdIOAPI.h"
#include "glmAlembic.h"

namespace glm
{
	namespace crowdio
	{
		class GLM_CROWDIO_API AlembicSkeleton
		{
		public:
			// Inner class that stores the vertices, normals et uvs for a sample of polymesh
			class GLM_CROWDIO_API Sample
			{
			public:
				Sample(size_t nbBones, size_t floatPPCount, size_t vecPPCount);
				virtual ~Sample();

				/**
				* \brief Deletes inner data
				*/
				void release();

				/**
				* \brief Compute the bounds
				*/
				void computeBoundingBox();

				bool								 _visible;		// skeleton visibility on this sample
				::Alembic::AbcGeom::Abc::uint64_t*   _id;				// entity ids
				::Alembic::AbcGeom::Abc::int64_t*   _entityId;			// entity ids
				::Alembic::AbcGeom::Abc::uint16_t*  _boneIds;			// bone ids
				::Alembic::AbcGeom::Abc::string*	_boneNames;			// bone names
				::Alembic::AbcGeom::Abc::float32_t* _bonePositions;		// positions
				::Alembic::AbcGeom::Abc::Quatf*		_boneOrientations;	// ori
				::Alembic::AbcGeom::Abc::float32_t* _boneScales;		// scales

				::Alembic::AbcGeom::Abc::int16_t*   _characterId;		// characters ids
				::Alembic::AbcGeom::Abc::uint16_t*  _geoFileId;			// geoFile ids

				::Alembic::AbcGeom::Abc::float32_t* _floatPPAttrs;		// float PP
				::Alembic::AbcGeom::Abc::float32_t* _vecPPAttrs;		// vec PP

				::Alembic::AbcGeom::Abc::Box3d		_bounds;			// bbox
				size_t								_boneCount;			// bone count
			};

			//************************************************************
			/*! @name Contructor
			*/ //*********************************************************
			//@{
			AlembicSkeleton(const GlmString&, size_t, size_t, size_t, const glm::Array<GlmString>&, const glm::Array<GlmString>&);
			virtual ~AlembicSkeleton();
			//@}

			//************************************************************
			/*! @name Accessors
			*/ //*********************************************************
			//@{

			/**
			* \brief Returns the name of the Skeleton
			*/
			const GlmString& getName() const;

			/**
			* \brief Returns the number of polymeshes
			*/
			const size_t getNbBones() const;
			const size_t getNbFloatPPAttr() const;
			const size_t getNbVecPPAttr() const;

			/**
			* \brief Returns the number of samples for the polymesh
			*/
			size_t getNbSamples() const;
			///@}

			/**
			* \brief Adds a new sample for the polymesh
			*/
			void addNewSample();

			/**
			* \brief Gets the sample for the polymesh
			* \param iSample The sample index to get
			*/
			const Sample* getSampleAt(size_t iSample);

			/**
			* \brief Gets the sample for the polymesh
			* \param iSample The sample index to get
			*/
			Sample* touchSampleAt(size_t iSample);

			/**
			* \brief Gets the last sample for the polymesh
			*/
			Sample* getLastSample();
			//@}

			//************************************************************
			/*! @name Data Members
			*/ //*********************************************************
			//@{
			GlmString _name; // The name of the Character
			size_t _boneCount;
			size_t _floatPPCount;
			size_t _vecPPCount;

			glm::Array<GlmString> _floatPPNames;
			glm::Array<GlmString> _vecPPNames;
			
			glm::PODArray<Sample*> _samples; // Samples
			int _currentSampleIndex; // The indice of the current sample
			//@}
		};
	}
}

#endif // GLM_EXPORT_ALEMBIC
