< Summary

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

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
AvatarRendererHelpers()0%2100%
RandomizeAndApplyGenericImpostor(...)0%2100%
ResetImpostorMeshUVs(...)0%2100%
SetImpostorTexture(...)0%6200%

File(s)

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

#LineLine coverage
 1using UnityEngine;
 2
 3namespace DCL
 4{
 5    public static class AvatarRendererHelpers
 6    {
 07        private static readonly int IMPOSTOR_TEXTURE_PROPERTY = Shader.PropertyToID("_BaseMap");
 8        private const bool ONLY_GENERIC_IMPOSTORS = false;
 9
 10        // 2048x2048 atlas with 8 512x1024 snapshot-sprites
 11        private const int GENERIC_IMPOSTORS_ATLAS_COLUMNS = 4;
 12        private const int GENERIC_IMPOSTORS_ATLAS_ROWS = 2;
 13
 14        public static void RandomizeAndApplyGenericImpostor(Mesh impostorMesh)
 15        {
 016            Vector2 spriteSize = new Vector2(1f / GENERIC_IMPOSTORS_ATLAS_COLUMNS, 1f / GENERIC_IMPOSTORS_ATLAS_ROWS);
 017            float randomUVXPos = Random.Range(0, GENERIC_IMPOSTORS_ATLAS_COLUMNS) * spriteSize.x;
 018            float randomUVYPos = Random.Range(0, GENERIC_IMPOSTORS_ATLAS_ROWS) * spriteSize.y;
 19
 020            Vector2[] uvs = new Vector2[4]; // Quads have only 4 vertices
 021            uvs[0].Set(randomUVXPos, randomUVYPos);
 022            uvs[1].Set(randomUVXPos + spriteSize.x, randomUVYPos);
 023            uvs[2].Set(randomUVXPos, randomUVYPos + spriteSize.y);
 024            uvs[3].Set(randomUVXPos + spriteSize.x, randomUVYPos + spriteSize.y);
 025            impostorMesh.uv = uvs;
 026        }
 27
 28        private static void ResetImpostorMeshUVs(Mesh impostorMesh)
 29        {
 030            Vector2[] uvs = new Vector2[4]; // Quads have only 4 vertices
 031            uvs[0].Set(0, 0);
 032            uvs[1].Set(1, 0);
 033            uvs[2].Set(0, 1);
 034            uvs[3].Set(1, 1);
 035            impostorMesh.uv = uvs;
 036        }
 37
 38        public static void SetImpostorTexture(Texture2D impostorTexture, Mesh impostorMesh, Material impostorMaterial)
 39        {
 040            if (ONLY_GENERIC_IMPOSTORS || impostorTexture == null)
 041                return;
 42
 043            ResetImpostorMeshUVs(impostorMesh);
 44
 045            impostorMaterial.SetTexture(IMPOSTOR_TEXTURE_PROPERTY, impostorTexture);
 046        }
 47    }
 48}