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

#ifndef GLM_FURDATA_H
#define GLM_FURDATA_H

#include <glmCrowdIOAPI.h>
#include "stdint.h"

namespace glm
{
	namespace crowdio
	{
		//-------------------------------------------------------------------------
		// Fur Cache Data Types
		// this class is only used for the Python API usage
		//-------------------------------------------------------------------------

		// Fur Skin Vertex Data ---------------------------------------------------
		typedef struct GlmFurSkinVertexData_v0
		{
			float _blendWeight; // 0.f for linear, 1.f for dual Q, between for blend
			uint16_t _skinInfluenceCount;
			float*	 _skinInfluenceWeights;
			int32_t* _skinInfluenceBoneIds;
		} GlmFurSkinVertexData_v0;
		typedef GlmFurSkinVertexData_v0 GlmFurSkinVertexData;

		// Fur Curve Group Data ---------------------------------------------------
		typedef struct GlmFurCurveGroupData_v0
		{
			uint32_t _curveCount;
			uint32_t _vertCount;
			uint32_t* _numVertices;			// number of vertices for each curve, array size = _curveCount
			uint32_t* _iCurveOffset;		// index in pos/width/uvs array for each curve, array size = _curveCount
			float(* _positions)[3];			// positions of vertices for each curve, array_size = sum(_numVertices) ie _vertCount
			float* _widths;					// widths of vertices for each curve, or empty, array_size = sum(_numVertices) ie _vertCount
			float(* _uvs)[2];				// uvs of vertices for each curve, or empty, array_size = sum(_numVertices) ie _vertCount

			// additional data from the associated geometry
			int _supportMeshId;             // support mesh id of each curve of this group (useful if no skinning)
			int* _triVtxIds;				// support mesh vertex indices for barycenter computation, array_size = 3 * _curveCount
			float(*_tetraBaryCoords)[3];	// support mesh terahedron barycenter if no skinning, array_size = sum(_vertices) ie _vertCount

			// degree & skinning info - since v2
			
			char _curveDegrees;				// degree for each curve
			bool _hasSkinningType;			// if true, the group has skinning type
			short* _skinningType;			// skinning type for each curve, values are FurSkinningType::Value, array_size = curveCount
			bool _hasSkinningInfo;			// if true, the group has skinning type
			GlmFurSkinVertexData* _skinningInfo; // vertex skinning info - per vertex, array_size = sum(_numVertices) ie _vertCount
		} GlmFurCurveGroupData_v0;
		typedef GlmFurCurveGroupData_v0 GlmFurCurveGroupData;

		// Fur Data ---------------------------------------------------------------
		typedef struct GlmFurData_v0
		{
			uint16_t _curveGroupsCount;
			GlmFurCurveGroupData* _curveGroups;

			GlmFurCurveGroupData* getCurveGroup(uint16_t _curveGroupsIdx)
			{
				return &_curveGroups[_curveGroupsIdx];
			}
		} GlmFurData_v0;
		typedef GlmFurData_v0 GlmFurData;

		// Utils Data -------------------------------------------------------------
		extern GLM_CROWDIO_API void createAndReadFurData(GlmFurData** furData , const char* file);
		extern GLM_CROWDIO_API void writeFurData(const char* file, const GlmFurData* furData);
		extern GLM_CROWDIO_API void destroyFurData(GlmFurData** furData);
		extern GLM_CROWDIO_API void setFurWidths(GlmFurData* furData, float baseWidth, float tipWidth);
		
	}
}

#endif // GLM_FURDATA_H
