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

#pragma once

#include <glmSDKAPI.h>
#include <glmString.h>
#include <glmArray.h>
#include <glmApex.h>

namespace glm
{
    class GenericSpecificConverter;
    class Vector3;
    class Vector2;

    struct ApexMaterial
    {
        ApexMaterial()
            : _materialName("default")
            , _verticalStretchingStiffness(1)
            , _horizontalStretchingStiffness(1)
            , _bendingStiffness(0.5f)
            , _shearingStiffness(0.5f)
            , _tetherStiffness(1)
            , _tetherLimit(1)
            , _verticalStiffnessScaling_compressionRange(1)
            , _verticalStiffnessScaling_stretchRange(1)
            , _verticalStiffnessScaling_scale(0.5f)
            , _horizontalStiffnessScaling_compressionRange(1)
            , _horizontalStiffnessScaling_stretchRange(1)
            , _horizontalStiffnessScaling_scale(0.5f)
            , _bendingStiffnessScaling_compressionRange(1)
            , _bendingStiffnessScaling_stretchRange(1)
            , _bendingStiffnessScaling_scale(0.5f)
            , _shearingStiffnessScaling_compressionRange(1)
            , _shearingStiffnessScaling_stretchRange(1)
            , _shearingStiffnessScaling_scale(0.5f)
            , _damping(0.1f)
            , _stiffnessFrequency(100)
            , _drag(0.f)
            , _friction(0.5f)
            , _massScale(25)
            , _gravityScale(1)
            , _inertiaScale(0.5f)
            , _solverIterations(5)
            , _solverFrequency(250)
        {
        }

        GlmString _materialName;
        float _verticalStretchingStiffness;
        float _horizontalStretchingStiffness;
        float _bendingStiffness;
        float _shearingStiffness;
        float _tetherStiffness;
        float _tetherLimit;
        //verticalStiffnessScaling
        float _verticalStiffnessScaling_compressionRange;
        float _verticalStiffnessScaling_stretchRange;
        float _verticalStiffnessScaling_scale;
        //horizontalStiffnessScaling
        float _horizontalStiffnessScaling_compressionRange;
        float _horizontalStiffnessScaling_stretchRange;
        float _horizontalStiffnessScaling_scale;
        //bendingStiffnessScaling
        float _bendingStiffnessScaling_compressionRange;
        float _bendingStiffnessScaling_stretchRange;
        float _bendingStiffnessScaling_scale;
        //shearingStiffnessScaling
        float _shearingStiffnessScaling_compressionRange;
        float _shearingStiffnessScaling_stretchRange;
        float _shearingStiffnessScaling_scale;

        float _damping;
        float _stiffnessFrequency;
        float _drag;
        float _friction;

		float _massScale;
        float _gravityScale;
        float _inertiaScale;

        unsigned int _solverIterations;
        float _solverFrequency;
    };

    nvidia::apex::Asset GLM_SDK_API* loadApexAsset(const char* fullpath, const char* assetName);
    nvidia::apex::ClothingAssetAuthoring GLM_SDK_API* createApexAsset(
        nvidia::apex::ApexSDK* _mApexSDK,
        nvidia::apex::ModuleClothing* mModuleClothing,
        const GenericSpecificConverter& genericSpecificConverter,
        const char* assetName,
        const glm::Array<int>& mIndices,
        const glm::Array<Vector3>& mVertices,
        const glm::Array<Vector3>& mNormals,
        const glm::Array<Vector2>& mTexCoords,
        const glm::Array<unsigned short>& mBoneIndices,
        const glm::Array<float>& mBoneWeights, //4 per vertex, so the size should be 4x the size of mVertices
        const glm::Array<float>& mMaxDistance,
        const glm::Array<float>& mCollisionSphereDistance,
        const glm::Array<float>& mCollisionSphereRadius,
        const glm::Array<unsigned char>& mUsedForPhysics,
        const glm::Array<int>& colliderBones,
        const ApexMaterial& material);
    bool GLM_SDK_API saveClothingAsset(nvidia::apex::ApexSDK* apexSDK, const char* filename, nvidia::apex::ClothingAssetAuthoring* asset);

} // namespace glm
