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

#pragma once

#include "glmSDKAPI.h"
#include "glmPhysicsWorld_PhysX.h"
#include "glmPhysicsDefinitions_PhysX.h"

//golaem core includes
#include <glmSimulation.h>

namespace  physx
{
	class PxMaterial;
}

namespace glm
{
	class MotionEntityTypeData;

	class GLM_SDK_API RagdollEntityTypeData_PhysX
	{

	public:	//methods
		GLM_CLASS_STAT_ID( glm::MemoryStatIds::Simulation);

		RagdollEntityTypeData_PhysX();
		~RagdollEntityTypeData_PhysX();

		void init(MotionEntityTypeData& motionEntityTypeData);
		void finish();

		int findParentRigidBodyIndex(const GenericSpecificConverter* converter, int rigidBodyIndex, const PODArray<unsigned int>* bonePhysicsConfigurationOverrideIndices = NULL, const Array<BonePhysicConfiguration>* bonePhysicsConfigurationOverrides = NULL);
		void getScaledShapes(glm::Array<shapePair*>& retShapes, const MotionEntityTypeData& motionEntityTypeData, const Array<Vector3>& boneScales, const PODArray<unsigned int>& bonePhysicsConfigurationOverrideIndices, const Array<BonePhysicConfiguration>& bonePhysicsConfigurationOverride, CollisionFilterMode::Value collisionFilterMode, bool useTriggerShapes);

	public:	//data
		int _nbRigidBodies;
		
		int* _rigidBodiesBonesCorrespondance;	//array of corresponding specific bone index: iSpecificBoneIndex = _rigidBodiesBonesCorrespondance[iRigidBody]
		int* _rigidBodiesBonesCorrespondanceInverse;	//array of corresponding rigid body index: iRigidBody = _rigidBodiesBonesCorrespondanceInverse[iSpecificBoneIndex] (warning: may return -1 if not rigid body exists for a given specific bone)

		Quaternion* _rigidBodiesLocalBaseInverseOri;	//array of inverse base local orientation for each rigid body (in the parent rigid body's coordinate system)

		//shared physX objects
		glm::Array<glm::GlmMap<Vector3, shapePair > > _rigidBodyShapes;	//array of shapes for each rigid body index, per scale
		glm::Array<shapePair*> _physicsOverrideRigidBodyShapes;		//stored to be destructed at finish
		glm::PODArray<physx::PxMaterial*> _rigidBodyMaterials;		//array of materiel for each rigid body index

	private:
		friend class PhysicsContext_PhysX;
	};
}
