//------------------------------------------------------------------------------------
// irr::scene::IAnimatedMeshB3d wrappers (parent is IAnimatedMesh)
//------------------------------------------------------------------------------------

extern "C"
{

	s32 IrrScene_IAnimatedMeshB3d_getJointCount(IAnimatedMeshB3d* am)
	{
		if (am)
			return am->getJointCount();
		else return 0;
	}
	
	const c8* IrrScene_IAnimatedMeshB3d_getJointName(IAnimatedMeshB3d* am,s32 number)
	{
		if (am)
			return am->getJointName(number);
		else return "";
	}
	
	s32 IrrScene_IAnimatedMeshB3d_getJointNumber(IAnimatedMeshB3d* am,const c8* name)
	{
		if (am)
			return am->getJointNumber(name);
		else return 0;
	}
	
	matrix4* IrrScene_IAnimatedMeshB3d_getMatrixOfJoint(IAnimatedMeshB3d* am,s32 jointNumber,s32 frame)
	{
		if (am)
			return am->getMatrixOfJoint(jointNumber,frame);
		else return 0;
	}
	
	matrix4* IrrScene_IAnimatedMeshB3d_getMatrixOfJointUnanimated(IAnimatedMeshB3d* am,s32 jointNumber)
	{
		if (am)
			return am->getMatrixOfJointUnanimated(jointNumber);
		else return 0;
	}

	matrix4* IrrScene_IAnimatedMeshB3d_getLocalMatrixOfJoint(IAnimatedMeshB3d* am,s32 jointNumber)
	{
		if (am)
			return am->getLocalMatrixOfJoint(jointNumber);
		else return 0;
	}
	
	void IrrScene_IAnimatedMeshB3d_setJointAnimation(IAnimatedMeshB3d* am,s32 jointNumber, bool On)
	{
		if (am)
			am->setJointAnimation(jointNumber,On);
	}
	
	void IrrScene_IAnimatedMeshB3d_setInterpolationMode(IAnimatedMeshB3d* am,s32 mode)
	{
		if (am)
			am->setInterpolationMode(mode);
	}
	
	void IrrScene_IAnimatedMeshB3d_setAnimateMode(IAnimatedMeshB3d* am,s32 mode)
	{
		if (am)
			am->setAnimateMode(mode);
	}

	void IrrScene_IAnimatedMeshB3d_updateNormalsWhenAnimating(IAnimatedMeshB3d* am,bool on)
	{
		if (am)
			am->updateNormalsWhenAnimating(on);
	}
		
	void IrrScene_IAnimatedMeshB3d_convertToTangents(IAnimatedMeshB3d* am)
	{
		if (am)
			am->convertToTangents();
	}
	
	// does not modify JointChildSceneNodes
	void IrrScene_IAnimatedMeshB3d_recoverJointsFromMesh(IAnimatedMeshB3d* am,ISceneNode** JointChildSceneNodeArray,u32 JointChildSceneNodeArraySize)
	{
		if (am) {
			
			array<ISceneNode*> JointChildSceneNodes;
			JointChildSceneNodes.set_pointer(JointChildSceneNodeArray,JointChildSceneNodeArraySize);
			JointChildSceneNodes.set_free_when_destroyed(false);

			/*
			array<ISceneNode*> JointChildSceneNodes(JointChildSceneNodeArraySize);
			for (int i=0; i<JointChildSceneNodeArraySize; i++) {	
				JointChildSceneNodes[i]=JointChildSceneNodeArray[i];
			}
			*/
			
			am->recoverJointsFromMesh(JointChildSceneNodes);
		}
	}
	
	// does not modify JointChildSceneNodes
	void IrrScene_IAnimatedMeshB3d_tranferJointsToMesh(IAnimatedMeshB3d* am,ISceneNode** JointChildSceneNodeArray,u32 JointChildSceneNodeArraySize)
	{
		if (am) {
			array<ISceneNode*> JointChildSceneNodes;
			JointChildSceneNodes.set_pointer(JointChildSceneNodeArray,JointChildSceneNodeArraySize);
			JointChildSceneNodes.set_free_when_destroyed(false);

			/*
			array<ISceneNode*> JointChildSceneNodes(JointChildSceneNodeArraySize);
			for (int i=0; i<JointChildSceneNodeArraySize; i++) {	
				JointChildSceneNodes[i]=JointChildSceneNodeArray[i];
			}
			*/

			am->tranferJointsToMesh(JointChildSceneNodes);
		}
	}

	s32 IrrScene_IAnimatedMeshB3d_createJoints(IAnimatedMeshB3d* am,ISceneNode* AnimatedMeshSceneNode, ISceneManager* SceneManager,u32** ptr)
	{
		if (am) {
			core::array<ISceneNode*> JointChildSceneNodes;
			JointChildSceneNodes.set_free_when_destroyed(false);
			
			am->createJoints(JointChildSceneNodes,AnimatedMeshSceneNode,SceneManager);

			Irr_ptrarray_allocate(ptr,JointChildSceneNodes.size());
			
			for (int i=0; i<JointChildSceneNodes.size(); i++) {
				((u32*)*ptr)[i]=(u32)JointChildSceneNodes[i];
			}
			
			return JointChildSceneNodes.size();
		} else return 0;
	}	
}



