| | 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 | | /// In the future, we may want to add a Renderer[] list here. |
| | 13 | | /// |
| | 14 | | /// With this in place, the SceneBoundsChecker and CullingController implementations can |
| | 15 | | /// be changed to be reactive, and lots of FindObjects and GetComponentsInChildren calls can be |
| | 16 | | /// saved. |
| | 17 | | /// </summary> |
| | 18 | | public class Rendereable : ICloneable |
| | 19 | | { |
| | 20 | | public string ownerId; |
| | 21 | | public GameObject container; |
| 291 | 22 | | public List<Mesh> meshes = new List<Mesh>(); |
| 291 | 23 | | public Dictionary<Mesh, int> meshToTriangleCount = new Dictionary<Mesh, int>(); |
| 291 | 24 | | public List<Renderer> renderers = new List<Renderer>(); |
| | 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 List<Renderer>(renderers); |
| 0 | 37 | | result.meshes = new List<Mesh>(meshes); |
| 0 | 38 | | return result; |
| | 39 | | } |
| | 40 | |
|
| | 41 | | public static Rendereable CreateFromGameObject(GameObject go) |
| | 42 | | { |
| 7 | 43 | | Rendereable rendereable = new Rendereable(); |
| 7 | 44 | | rendereable.container = go; |
| 7 | 45 | | rendereable.renderers = go.GetComponentsInChildren<Renderer>().ToList(); |
| 7 | 46 | | rendereable.meshes = MeshesInfoUtils.ExtractMeshes(go); |
| 7 | 47 | | rendereable.meshToTriangleCount = MeshesInfoUtils.ExtractMeshToTriangleMap(rendereable.meshes); |
| 7 | 48 | | rendereable.totalTriangleCount = MeshesInfoUtils.ComputeTotalTriangles(rendereable.renderers, rendereable.me |
| 7 | 49 | | return rendereable; |
| | 50 | | } |
| | 51 | | } |
| | 52 | | } |