Esempio n. 1
0
        void AddMaterial(EntityMetrics entityMetrics, Material material)
        {
            if (material == null)
            {
                return;
            }

            if (!uniqueMaterialsRefCount.ContainsKey(material))
            {
                uniqueMaterialsRefCount.Add(material, 1);
            }
            else
            {
                uniqueMaterialsRefCount[material] += 1;
            }

            if (!entityMetrics.materials.ContainsKey(material))
            {
                entityMetrics.materials.Add(material, 1);
            }
            else
            {
                entityMetrics.materials[material] += 1;
            }
        }
        void CalculateMaterials(DecentralandEntity entity, EntityMetrics entityMetrics)
        {
            var originalMaterials = Environment.i.world.sceneBoundsChecker.GetOriginalMaterials(entity.meshesInfo);

            int originalMaterialsCount = originalMaterials.Count;

            for (int i = 0; i < originalMaterialsCount; i++)
            {
                AddMaterial(entityMetrics, originalMaterials[i]);

                if (VERBOSE)
                {
                    Debug.Log($"SceneMetrics: material (style: {Environment.i.world.sceneBoundsChecker.GetFeedbackStyle().GetType().FullName}) {originalMaterials[i].name} of entity {entity.entityId}");
                }
            }
        }
Esempio n. 3
0
        void RemoveEntitiesMaterial(EntityMetrics entityMetrics)
        {
            var entityMaterials = entityMetrics.materials;

            using (var iterator = entityMaterials.GetEnumerator())
            {
                while (iterator.MoveNext())
                {
                    if (uniqueMaterialsRefCount.ContainsKey(iterator.Current.Key))
                    {
                        uniqueMaterialsRefCount[iterator.Current.Key] -= iterator.Current.Value;
                        if (uniqueMaterialsRefCount[iterator.Current.Key] <= 0)
                        {
                            uniqueMaterialsRefCount.Remove(iterator.Current.Key);
                        }
                    }
                }
            }
        }
Esempio n. 4
0
        void CalculateMaterials(DecentralandEntity entity, EntityMetrics entityMetrics)
        {
            //get boundaries checker if in debug cause it may have swap meshes materials
            var debugBoundariesChecker = SceneController.i.boundariesChecker as SceneBoundariesDebugModeChecker;

            //can we count materials directly from the mesh renderers?
            bool isInValidPosition = debugBoundariesChecker == null ||
                                     (debugBoundariesChecker != null && debugBoundariesChecker.WasEntityInAValidPosition(entity));

            isInValidPosition |= !SceneController.i.useBoundariesChecker;

            if (isInValidPosition)
            {
                for (int i = 0; i < entity.meshesInfo.renderers.Length; i++)
                {
                    Renderer renderer = entity.meshesInfo.renderers[i];
                    for (int j = 0; j < renderer.sharedMaterials.Length; j++)
                    {
                        Material m = renderer.sharedMaterials[j];
                        AddMaterial(entityMetrics, m);
                        if (VERBOSE)
                        {
                            Debug.Log("SceneMetrics: material (from renderer) " + m.name + " of entity " + entity.entityId);
                        }
                    }
                }
            }
            else
            {
                var meshOriginalMaterialsDic = debugBoundariesChecker.GetOriginalMaterials(entity);
                using (var iterator = meshOriginalMaterialsDic.GetEnumerator())
                {
                    while (iterator.MoveNext())
                    {
                        AddMaterial(entityMetrics, iterator.Current.Value);
                        if (VERBOSE)
                        {
                            Debug.Log("SceneMetrics: material (from debugBoundariesChecker) " + iterator.Current.Value.name + " of entity " + entity.entityId);
                        }
                    }
                }
            }
        }
Esempio n. 5
0
        void AddMesh(EntityMetrics entityMetrics, Mesh mesh)
        {
            if (!uniqueMeshesRefCount.ContainsKey(mesh))
            {
                uniqueMeshesRefCount.Add(mesh, 1);
            }
            else
            {
                uniqueMeshesRefCount[mesh] += 1;
            }

            if (!entityMetrics.meshes.ContainsKey(mesh))
            {
                entityMetrics.meshes.Add(mesh, 1);
            }
            else
            {
                entityMetrics.meshes[mesh] += 1;
            }
        }
Esempio n. 6
0
        protected void SubstractMetrics(IDCLEntity entity)
        {
            if (!entitiesMetrics.ContainsKey(entity))
            {
                return;
            }

            EntityMetrics entityMetrics = entitiesMetrics[entity];

            RemoveEntitiesMaterial(entityMetrics);
            RemoveEntityMeshes(entityMetrics);

            model.materials  = uniqueMaterialsRefCount.Count;
            model.meshes     = uniqueMeshesRefCount.Count;
            model.triangles -= entityMetrics.triangles;
            model.bodies    -= entityMetrics.bodies;

            if (entitiesMetrics.ContainsKey(entity))
            {
                entitiesMetrics.Remove(entity);
            }

            isDirty = true;
        }
Esempio n. 7
0
 public void Initialise()
 {
     TestObject = new EntityMetrics(Factory.GetRealisationEntity());
     Assert.IsNotNull(TestObject, "Failed to instantiate TestObject.");
 }
Esempio n. 8
0
        protected void AddMetrics(IDCLEntity entity)
        {
            if (entity.meshRootGameObject == null)
            {
                return;
            }

            // If the mesh is being loaded we should skip the evaluation (it will be triggered again later when the loading finishes)
            if (entity.meshRootGameObject.GetComponent <MaterialTransitionController>()) // the object's MaterialTransitionController is destroyed when it finishes loading
            {
                return;
            }

            EntityMetrics entityMetrics = new EntityMetrics();

            int visualMeshRawTriangles = 0;

            //NOTE(Brian): If this proves to be too slow we can spread it with a Coroutine spooler.
            MeshFilter[] meshFilters = entity.meshesInfo.meshFilters;

            for (int i = 0; i < meshFilters.Length; i++)
            {
                MeshFilter mf = meshFilters[i];

                if (mf != null && mf.sharedMesh != null)
                {
                    visualMeshRawTriangles += mf.sharedMesh.triangles.Length;
                    AddMesh(entityMetrics, mf.sharedMesh);
                    if (VERBOSE)
                    {
                        Debug.Log("SceneMetrics: tris count " + mf.sharedMesh.triangles.Length + " from mesh " + mf.sharedMesh.name + " of entity " + entity.entityId);
                        Debug.Log("SceneMetrics: mesh " + mf.sharedMesh.name + " of entity " + entity.entityId);
                    }
                }
            }

            CalculateMaterials(entity, entityMetrics);

            //The array is a list of triangles that contains indices into the vertex array. The size of the triangle array must always be a multiple of 3.
            //Vertices can be shared by simply indexing into the same vertex.
            entityMetrics.triangles = visualMeshRawTriangles / 3;
            entityMetrics.bodies    = entity.meshesInfo.meshFilters.Length;

            model.materials  = uniqueMaterialsRefCount.Count;
            model.meshes     = uniqueMeshesRefCount.Count;
            model.triangles += entityMetrics.triangles;
            model.bodies    += entityMetrics.bodies;

            if (!entitiesMetrics.ContainsKey(entity))
            {
                entitiesMetrics.Add(entity, entityMetrics);
            }
            else
            {
                entitiesMetrics[entity] = entityMetrics;
            }

            if (VERBOSE)
            {
                Debug.Log("SceneMetrics: entity " + entity.entityId + " metrics " + entityMetrics.ToString());
            }

            isDirty = true;
        }