< Summary

Class:DCL.AvatarRendererHelpers
Assembly:AvatarRendererHelpers
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Components/Avatar/AvatarRendererHelpers/AvatarRendererHelpers.cs
Covered lines:17
Uncovered lines:20
Coverable lines:37
Total lines:81
Line coverage:45.9% (17 of 37)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
AvatarRendererHelpers()0%110100%
RandomizeAndApplyGenericImpostor(...)0%2100%
ResetImpostorMeshUVs(...)0%110100%
SetImpostorTexture(...)0%2.032080%
SetImpostorTintColor(...)0%2100%
CalculateImpostorTint(...)0%2100%
ResetImpostor(...)0%110100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Components/Avatar/AvatarRendererHelpers/AvatarRendererHelpers.cs

#LineLine coverage
 1using UnityEngine;
 2
 3namespace DCL
 4{
 5    public static class AvatarRendererHelpers
 6    {
 17        private static readonly int IMPOSTOR_TEXTURE_PROPERTY = Shader.PropertyToID("_BaseMap");
 18        private static readonly int IMPOSTOR_TEXTURE_COLOR_PROPERTY = Shader.PropertyToID("_BaseColor");
 9
 10        // Manually tweaked values
 111        public static readonly float IMPOSTOR_MOVEMENT_INTERPOLATION = 1.79f;
 12        private const float IMPOSTOR_TINT_MIN_DISTANCE = 30f;
 13        private const float IMPOSTOR_TINT_MAX_DISTANCE = 81.33f;
 14        private const float IMPOSTOR_TINT_NEAREST_BLACKNESS = 0f;
 15        private const float IMPOSTOR_TINT_FAREST_BLACKNESS = 0.74f;
 16
 17        // 2048x2048 atlas with 8 512x1024 snapshot-sprites
 18        private const int GENERIC_IMPOSTORS_ATLAS_COLUMNS = 4;
 19        private const int GENERIC_IMPOSTORS_ATLAS_ROWS = 2;
 20
 121        private static Texture2D genericImpostorsTexture = Resources.Load<Texture2D>("Textures/avatar-impostors-atlas");
 122        private static Texture2D transparentPixelTexture = Resources.Load<Texture2D>("Textures/transparent-pixel");
 23
 24        public static void RandomizeAndApplyGenericImpostor(Mesh impostorMesh, Material impostorMaterial)
 25        {
 026            SetImpostorTexture(genericImpostorsTexture, impostorMesh, impostorMaterial);
 27
 028            Vector2 spriteSize = new Vector2(1f / GENERIC_IMPOSTORS_ATLAS_COLUMNS, 1f / GENERIC_IMPOSTORS_ATLAS_ROWS);
 029            float randomUVXPos = Random.Range(0, GENERIC_IMPOSTORS_ATLAS_COLUMNS) * spriteSize.x;
 030            float randomUVYPos = Random.Range(0, GENERIC_IMPOSTORS_ATLAS_ROWS) * spriteSize.y;
 31
 032            Vector2[] uvs = new Vector2[4]; // Quads have only 4 vertices
 033            uvs[0].Set(randomUVXPos, randomUVYPos);
 034            uvs[1].Set(randomUVXPos + spriteSize.x, randomUVYPos);
 035            uvs[2].Set(randomUVXPos, randomUVYPos + spriteSize.y);
 036            uvs[3].Set(randomUVXPos + spriteSize.x, randomUVYPos + spriteSize.y);
 037            impostorMesh.uv = uvs;
 038        }
 39
 40        private static void ResetImpostorMeshUVs(Mesh impostorMesh)
 41        {
 132742            Vector2[] uvs = new Vector2[4]; // Quads have only 4 vertices
 132743            uvs[0].Set(0, 0);
 132744            uvs[1].Set(1, 0);
 132745            uvs[2].Set(0, 1);
 132746            uvs[3].Set(1, 1);
 132747            impostorMesh.uv = uvs;
 132748        }
 49
 50        public static void SetImpostorTexture(Texture2D impostorTexture, Mesh impostorMesh, Material impostorMaterial)
 51        {
 132752            if (TextureUtils.IsQuestionMarkPNG(impostorTexture))
 053                return;
 54
 132755            ResetImpostorMeshUVs(impostorMesh);
 56
 132757            impostorMaterial.SetTexture(IMPOSTOR_TEXTURE_PROPERTY, impostorTexture);
 132758        }
 59
 60        /// <summary>
 61        /// Sets impostor texture tint color ignoring the alpha channel
 62        /// </summary>
 63        public static void SetImpostorTintColor(Material impostorMaterial, Color newColor)
 64        {
 065            newColor.a = impostorMaterial.GetColor(IMPOSTOR_TEXTURE_COLOR_PROPERTY).a;
 066            impostorMaterial.SetColor(IMPOSTOR_TEXTURE_COLOR_PROPERTY, newColor);
 067        }
 68
 69        public static Color CalculateImpostorTint(float distanceToMainPlayer)
 70        {
 071            float initialStep = Mathf.Max(IMPOSTOR_TINT_MIN_DISTANCE, distanceToMainPlayer);
 072            float tintStep = Mathf.InverseLerp(IMPOSTOR_TINT_MIN_DISTANCE, IMPOSTOR_TINT_MAX_DISTANCE, initialStep);
 073            float tintValue = Mathf.Lerp(IMPOSTOR_TINT_NEAREST_BLACKNESS, IMPOSTOR_TINT_FAREST_BLACKNESS, tintStep);
 074            Color newColor = Color.Lerp(Color.white, Color.black, tintValue);
 75
 076            return newColor;
 77        }
 78
 265479        public static void ResetImpostor(Mesh impostorMesh, Material impostorMaterial) { SetImpostorTexture(transparentP
 80    }
 81}