| | 1 | | using System; |
| | 2 | | using System.Collections.Generic; |
| | 3 | | using System.Linq; |
| | 4 | | using DCL.Models; |
| | 5 | | using UnityEngine; |
| | 6 | |
|
| | 7 | | namespace DCL |
| | 8 | | { |
| | 9 | | /// <summary> |
| | 10 | | /// The Rendereable object represents any loaded object that should be visible in the world. |
| | 11 | | /// |
| | 12 | | /// With this in place, the SceneBoundsChecker, CullingController and SceneMetricsCounter |
| | 13 | | /// implementations can be changed to be reactive, and lots of FindObjects and GetComponentsInChildren |
| | 14 | | /// calls can be saved. |
| | 15 | | /// </summary> |
| | 16 | | public class Rendereable : ICloneable |
| | 17 | | { |
| | 18 | | public string ownerId; |
| | 19 | | public GameObject container; |
| 606 | 20 | | public Dictionary<Mesh, int> meshToTriangleCount = new Dictionary<Mesh, int>(); |
| 606 | 21 | | public HashSet<Mesh> meshes = new HashSet<Mesh>(); |
| 606 | 22 | | public HashSet<Renderer> renderers = new HashSet<Renderer>(); |
| 606 | 23 | | public HashSet<Material> materials = new HashSet<Material>(); |
| 606 | 24 | | public HashSet<Texture> textures = new HashSet<Texture>(); |
| | 25 | | public int totalTriangleCount = 0; |
| | 26 | |
|
| | 27 | | public bool Equals(Rendereable other) |
| | 28 | | { |
| 0 | 29 | | return container == other.container; |
| | 30 | | } |
| | 31 | |
|
| | 32 | | public object Clone() |
| | 33 | | { |
| 0 | 34 | | var result = (Rendereable)this.MemberwiseClone(); |
| 0 | 35 | | result.meshToTriangleCount = new Dictionary<Mesh, int>(meshToTriangleCount); |
| 0 | 36 | | result.renderers = new HashSet<Renderer>(renderers); |
| 0 | 37 | | result.materials = new HashSet<Material>(materials); |
| 0 | 38 | | result.textures = new HashSet<Texture>(textures); |
| 0 | 39 | | result.meshes = new HashSet<Mesh>(meshes); |
| 0 | 40 | | return result; |
| | 41 | | } |
| | 42 | |
|
| | 43 | | public static Rendereable CreateFromGameObject(GameObject go) |
| | 44 | | { |
| 19 | 45 | | Rendereable rendereable = new Rendereable(); |
| 19 | 46 | | rendereable.container = go; |
| 19 | 47 | | rendereable.renderers = MeshesInfoUtils.ExtractUniqueRenderers(go); |
| 19 | 48 | | rendereable.materials = MeshesInfoUtils.ExtractUniqueMaterials(rendereable.renderers); |
| 19 | 49 | | rendereable.textures = MeshesInfoUtils.ExtractUniqueTextures(rendereable.materials); |
| 19 | 50 | | rendereable.meshes = MeshesInfoUtils.ExtractUniqueMeshes(rendereable.renderers); |
| 19 | 51 | | rendereable.meshToTriangleCount = MeshesInfoUtils.ExtractMeshToTriangleMap(rendereable.meshes.ToList()); |
| 19 | 52 | | rendereable.totalTriangleCount = MeshesInfoUtils.ComputeTotalTriangles(rendereable.renderers, rendereable.me |
| | 53 | |
|
| 19 | 54 | | return rendereable; |
| | 55 | | } |
| | 56 | |
|
| | 57 | | public override string ToString() |
| | 58 | | { |
| 0 | 59 | | return $"Rendereable - owner: {ownerId} ... textures: {textures.Count} ... triangles: {totalTriangleCount} . |
| | 60 | | } |
| | 61 | | } |
| | 62 | | } |