include/geometry/PxHairSystemDesc.h

File members: include/geometry/PxHairSystemDesc.h

// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//  * Redistributions of source code must retain the above copyright
//    notice, this list of conditions and the following disclaimer.
//  * Redistributions in binary form must reproduce the above copyright
//    notice, this list of conditions and the following disclaimer in the
//    documentation and/or other materials provided with the distribution.
//  * Neither the name of NVIDIA CORPORATION nor the names of its
//    contributors may be used to endorse or promote products derived
//    from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Copyright (c) 2008-2023 NVIDIA Corporation. All rights reserved.

#ifndef PX_HAIRSYSTEM_DESC_H
#define PX_HAIRSYSTEM_DESC_H
#include "foundation/PxFlags.h"
#include "common/PxCoreUtilityTypes.h"

#if PX_ENABLE_FEATURES_UNDER_CONSTRUCTION

#if !PX_DOXYGEN
namespace physx
{
#endif

    struct PxHairSystemDescFlag
    {
        enum Enum
        {
            eDEVICE_MEMORY = (1<<0)
        };
    };

    typedef PxFlags<PxHairSystemDescFlag::Enum, PxU16> PxHairSystemDescFlags;
    PX_FLAGS_OPERATORS(PxHairSystemDescFlag::Enum, PxU16)

    class PxHairSystemDesc
    {
    public:
        PxU32 numStrands;

        PxReal segmentLength;

        PxReal segmentRadius;

        PxBoundedData numVerticesPerStrand;

        PxBoundedData vertices;

        PxBoundedData velocities;

        PxHairSystemDescFlags flags;

        PX_INLINE PxHairSystemDesc();

        PX_INLINE void setToDefault();

        PX_INLINE bool isValid() const;
    };

    PX_INLINE PxHairSystemDesc::PxHairSystemDesc()
    {
        numStrands = 0;
        segmentLength = 0.1f;
        segmentRadius = 0.01f;
    }

    PX_INLINE void PxHairSystemDesc::setToDefault()
    {
        *this = PxHairSystemDesc();
    }

    PX_INLINE bool PxHairSystemDesc::isValid() const
    {
        if (segmentLength < 0.0f || segmentRadius < 0.0f)
            return false;

        if (2.0f * segmentRadius >= segmentLength)
            return false;

        if (numStrands == 0)
            return false;

        if (numVerticesPerStrand.count != numStrands)
            return false;

        PxU32 totalNumVertices = 0;
        for (PxU32 i = 0; i < numVerticesPerStrand.count; i++)
        {
            const PxU32 numVertices = numVerticesPerStrand.at<PxU32>(i);
            totalNumVertices += numVertices;
            if (numVertices < 2)
            {
                return false;
            }
        }

        if (vertices.count != totalNumVertices && vertices.count != numStrands)
            return false;

        if (velocities.count != totalNumVertices && velocities.count != 0)
            return false;

        return true;
    }

#if !PX_DOXYGEN
} // namespace physx
#endif

#endif

#endif