AssetHelper.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include <Utils/AssetHelper.h>
  9. #include <Utils/MeshAssetHelper.h>
  10. namespace NvCloth
  11. {
  12. const int InvalidIndex = -1;
  13. AssetHelper::AssetHelper(AZ::EntityId entityId)
  14. : m_entityId(entityId)
  15. {
  16. }
  17. AZStd::unique_ptr<AssetHelper> AssetHelper::CreateAssetHelper(AZ::EntityId entityId)
  18. {
  19. return entityId.IsValid()
  20. ? AZStd::make_unique<MeshAssetHelper>(entityId)
  21. : nullptr;
  22. }
  23. float AssetHelper::ConvertBackstopOffset(float backstopOffset)
  24. {
  25. constexpr float ToleranceU8 = 1.0f / 255.0f;
  26. // Convert range from [0,1] -> [-1,1]
  27. backstopOffset = AZ::GetClamp(backstopOffset * 2.0f - 1.0f, -1.0f, 1.0f);
  28. // Since the color was stored as U32 in the mesh, the low precision makes values
  29. // of 0.5f becoming an small negative number in the conversion from [0,1] to [-1,1].
  30. // So this sets the value to 0 when it is smaller than the tolerance of U8.
  31. backstopOffset = (std::fabs(backstopOffset) < ToleranceU8) ? 0.0f : backstopOffset;
  32. return backstopOffset;
  33. }
  34. } // namespace NvCloth