Exemple #1
0
 private void SubmitMeshes(RetainedGizmos gizmos, ulong hash)
 {
     for (int i = 0; i < meshes.Count; i++)
     {
         gizmos.meshes.Add(new MeshWithHash {
             hash = hash, mesh = meshes[i], lines = false
         });
         gizmos.existingHashes.Add(hash);
     }
 }
Exemple #2
0
            public void DrawMesh(RetainedGizmos gizmos, Vector3[] vertices, List <int> triangles, Color[] colors)
            {
                var mesh = gizmos.GetMesh();

                mesh.vertices = vertices;
                mesh.SetTriangles(triangles, 0);
                mesh.colors = colors;

                mesh.UploadMeshData(true);
                meshes.Add(mesh);
            }
Exemple #3
0
 public void Init(NavSystem active, RetainedGizmos.Hasher hasher, RetainedGizmos gizmos)
 {
     if (active != null)
     {
         debugData      = active.debugHandler;
         debugPathID    = active.debugPathID;
         debugFloor     = active.debugFloor;
         debugRoof      = active.debugRoof;
         showSearchTree = active.showSearchTree && debugData != null;
     }
     this.gizmos = gizmos;
     this.hasher = hasher;
     builder     = Pool <RetainedGizmos.Builder> .Allocate();
 }
Exemple #4
0
            private void SubmitLines(RetainedGizmos gizmos, ulong hash)
            {
                const int MaxLineEndPointsPerBatch = 65532 / 2;
                int       batches = (lines.Count + MaxLineEndPointsPerBatch - 1) / MaxLineEndPointsPerBatch;

                for (int batch = 0; batch < batches; batch++)
                {
                    int startIndex        = MaxLineEndPointsPerBatch * batch;
                    int endIndex          = Mathf.Min(startIndex + MaxLineEndPointsPerBatch, lines.Count);
                    int lineEndPointCount = endIndex - startIndex;
                    UnityEngine.Assertions.Assert.IsTrue(lineEndPointCount % 2 == 0);

                    var vertices = ListPool <Vector3> .Claim(lineEndPointCount * 2);

                    var colors = ListPool <Color32> .Claim(lineEndPointCount * 2);

                    var normals = ListPool <Vector3> .Claim(lineEndPointCount * 2);

                    var uv = ListPool <Vector2> .Claim(lineEndPointCount * 2);

                    var tris = ListPool <int> .Claim(lineEndPointCount * 3);

                    for (int j = startIndex; j < endIndex; j++)
                    {
                        var vertex = (Vector3)lines[j];
                        vertices.Add(vertex);
                        vertices.Add(vertex);

                        var color = (Color32)lineColors[j];
                        colors.Add(color);
                        colors.Add(color);
                        uv.Add(new Vector2(0, 0));
                        uv.Add(new Vector2(1, 0));
                    }

                    for (int j = startIndex; j < endIndex; j += 2)
                    {
                        var lineDir = (Vector3)(lines[j + 1] - lines[j]);

                        normals.Add(lineDir);
                        normals.Add(lineDir);
                        normals.Add(lineDir);
                        normals.Add(lineDir);
                    }

                    for (int j = 0, v = 0; j < lineEndPointCount * 3; j += 6, v += 4)
                    {
                        // First triangle
                        tris.Add(v + 0);
                        tris.Add(v + 1);
                        tris.Add(v + 2);

                        // Second triangle
                        tris.Add(v + 1);
                        tris.Add(v + 3);
                        tris.Add(v + 2);
                    }

                    var mesh = gizmos.GetMesh();

                    mesh.SetVertices(vertices);
                    mesh.SetTriangles(tris, 0);
                    mesh.SetColors(colors);
                    mesh.SetNormals(normals);
                    mesh.SetUVs(0, uv);

                    mesh.UploadMeshData(true);

                    ListPool <Vector3> .Release(ref vertices);

                    ListPool <Color32> .Release(ref colors);

                    ListPool <Vector3> .Release(ref normals);

                    ListPool <Vector2> .Release(ref uv);

                    ListPool <int> .Release(ref tris);

                    gizmos.meshes.Add(new MeshWithHash {
                        hash = hash, mesh = mesh, lines = true
                    });
                    gizmos.existingHashes.Add(hash);
                }
            }
Exemple #5
0
 public void Submit(RetainedGizmos gizmos, Hasher hasher)
 {
     SubmitLines(gizmos, hasher.Hash);
     SubmitMeshes(gizmos, hasher.Hash);
 }