Beispiel #1
0
    private void Start()
    {
        if (static_mesh == null)
        {
            const float RADIUS = 1.2f;
            const float YD     = 0.015f;
            float       S      = Mathf.Sqrt(3f) * 0.5f;

            static_mesh = VelocityBooster.MakeLinesMesh(new List <Vector3>
            {
                RADIUS *new Vector3(1.0f, YD, 0),
                RADIUS * new Vector3(0.5f, YD, S),
                RADIUS * new Vector3(-0.5f, YD, S),
                RADIUS * new Vector3(-1.0f, YD, 0),
                RADIUS * new Vector3(-0.5f, YD, -S),
                RADIUS * new Vector3(0.5f, YD, -S),

                RADIUS * new Vector3(1.0f, -YD, 0),
                RADIUS * new Vector3(0.5f, -YD, S),
                RADIUS * new Vector3(-0.5f, -YD, S),
                RADIUS * new Vector3(-1.0f, -YD, 0),
                RADIUS * new Vector3(-0.5f, -YD, -S),
                RADIUS * new Vector3(0.5f, -YD, -S),
            },
                                                        new int[]
            {
                0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 0,
                6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 6,
            });
        }
    }
Beispiel #2
0
    Mesh GetVBMesh()
    {
        Mesh src_mesh = VelocityBoostCube() ? null : GetComponent <MeshFilter>().sharedMesh;

        string name = src_mesh ? src_mesh.name : "cube";

        if (!vb_static_meshes.TryGetValue(name, out Mesh mesh))
        {
            var vecs    = new List <Vector3>();
            var indices = new List <int>();

            if (!src_mesh)
            {
                /* cube */
                for (int dz = -1; dz <= 1; dz += 2)
                {
                    for (int dy = -1; dy <= 1; dy += 2)
                    {
                        for (int dx = -1; dx <= 1; dx += 2)
                        {
                            vecs.Add(new Vector3(dx * 0.5f, dy * 0.5f, dz * 0.5f));
                        }
                    }
                }

                indices.AddRange(new int[] {
                    0, 1, 2, 3, 4, 5, 6, 7,
                    0, 2, 1, 3, 4, 6, 5, 7,
                    0, 4, 1, 5, 2, 6, 3, 7,
                });
            }
            else
            {
                /* copy the underlying mesh's edges */
                var vec2index = new Dictionary <Vector3Int, int>();
                var seen_edge = new HashSet <System.Tuple <int, int> >();

                int AddVec(Vector3 v)
                {
                    Vector3Int key = Vector3Int.RoundToInt(v * 128f);

                    if (!vec2index.TryGetValue(key, out int i))
                    {
                        i = vecs.Count;
                        vecs.Add(v);
                        vec2index[key] = i;
                    }
                    return(i);
                }

                var src_vecs    = src_mesh.vertices;
                var src_indices = src_mesh.GetIndices(0);
                for (int i = 0; i < src_indices.Length; i++)
                {
                    int j = i + 1;
                    if ((j % 3) == 0)
                    {
                        j -= 3;
                    }

                    int ii = AddVec(src_vecs[src_indices[i]]);
                    int jj = AddVec(src_vecs[src_indices[j]]);

                    if (!seen_edge.Contains(System.Tuple.Create(ii, jj)) &&
                        !seen_edge.Contains(System.Tuple.Create(jj, ii)))
                    {
                        indices.Add(ii);
                        indices.Add(jj);
                        seen_edge.Add(System.Tuple.Create(jj, ii));
                    }
                }
            }

            mesh = VelocityBooster.MakeLinesMesh(vecs, indices.ToArray());
            vb_static_meshes[name] = mesh;
        }
        return(mesh);
    }