Ejemplo n.º 1
0
        Mesh GenerateStarsAsGeometryMesh(Star[] stars)
        {
            Mesh m = new Mesh();

            Vector3[] vertices = new Vector3[stars.Length];
            Color[]   colors   = new Color[stars.Length];

            int[] triangles = new int[stars.Length * 3];

            for (int i = 0; i < stars.Length; i++)
            {
                /*if (cullBelowHorizon &&
                 *  transform.TransformDirection(stars[i].position).y < 0)
                 *  continue;*/

                vertices[i] = stars[i].position.normalized * distance;

                colors[i]   = Starmap.GetColorFromColorIndex(stars[i].colorIndex);
                colors[i].a = Starmap.GetScaleFromMagnitude(stars[i].magnitude);

                triangles[i * 3]     = i;
                triangles[i * 3 + 1] = i;
                triangles[i * 3 + 2] = i;
            }

            m.vertices  = vertices;
            m.colors    = colors;
            m.triangles = triangles;

            return(m);
        }
Ejemplo n.º 2
0
        void Start()
        {
            if (!starData)
            {
                Debug.LogError("No StarData asset assigned to the renderer", this);

                enabled = false;
                return;
            }

            Star[] stars = starData.stars;

            List <Star> starsList = cullBelowHorizon ?
                                    starsList                         = Starmap.GetStarsCulledBelowHorizon(stars, transform.InverseTransformDirection(Vector3.up), cullBelowHorizonOffset) :
                                                            starsList = new List <Star>(stars);


            if (useCubicSplitting)
            {
                var cubicSplitStars = CubicSplit(starsList);

                foreach (var cs in cubicSplitStars)
                {
                    var splits = Starmap.SplitToMax(cs, Starmap.MESH_STAR_COUNT_LIMIT);

                    foreach (var chunk in splits)
                    {
                        Mesh m = GenerateStarsAsStaticQuadsMesh(chunk);

                        GameObject go = new GameObject("Stars");
                        go.AddComponent <MeshFilter>().sharedMesh = m;
                        go.AddComponent <MeshRenderer>().material = material;
                        go.transform.SetParent(gameObject.transform, false);
                    }
                }
            }
            else
            {
                var splits = Starmap.SplitToMax(starsList, Starmap.MESH_STAR_COUNT_LIMIT);

                foreach (var chunk in splits)
                {
                    Mesh m = GenerateStarsAsStaticQuadsMesh(chunk);

                    GameObject go = new GameObject("Stars");
                    go.AddComponent <MeshFilter>().sharedMesh = m;
                    go.AddComponent <MeshRenderer>().material = material;
                    go.transform.SetParent(gameObject.transform, false);
                }
            }
        }
Ejemplo n.º 3
0
        void Start()
        {
            if (!starData)
            {
                Debug.LogError("No StarData asset assigned to the renderer", this);

                enabled = false;
                return;
            }

            var stars = new List <Star>(starData.stars);

            var splits = Starmap.SplitToMax(stars, Starmap.MESH_STAR_COUNT_LIMIT);

            foreach (var chunk in splits)
            {
                Mesh m = GenerateStarsAsGeometryMesh(chunk);

                GameObject go = new GameObject("Stars");
                go.AddComponent <MeshFilter>().sharedMesh = m;
                go.AddComponent <MeshRenderer>().material = material;
                go.transform.SetParent(gameObject.transform, false);
            }
        }
Ejemplo n.º 4
0
 public void LoadFromDatabase(float magnitudeLimit)
 {
     stars = Starmap.LoadFromDatabase(magnitudeLimit);
 }
Ejemplo n.º 5
0
        Mesh GenerateStarsAsStaticQuadsMesh(Star[] stars)
        {
            Mesh m = new Mesh();

            int vertexCount = stars.Length * 4;

            Vector3[] vertices = new Vector3[vertexCount];
            Color[]   colors   = new Color[vertexCount];
            Vector2[] uvs      = new Vector2[vertexCount];

            int[] triangles = new int[stars.Length * 6];

            Vector2 uv0 = new Vector2(0, 0);
            Vector2 uv1 = new Vector2(1, 0);
            Vector2 uv2 = new Vector2(0, 1);
            Vector2 uv3 = new Vector2(1, 1);

            for (int i = 0; i < stars.Length; i++)
            {
                Vector3 v   = stars[i].position.normalized * distance;
                Vector3 dir = stars[i].position.normalized;

                Vector3 up = Vector3.ProjectOnPlane(Vector3.up, dir).normalized;
                Vector3 rt = Vector3.Cross(up, dir);

                float size = sizeByMagnitudeCurve.Evaluate(stars[i].magnitude);
                up *= 0.5f * size;
                rt *= 0.5f * size;

                int i0 = i * 4 + 0;
                int i1 = i * 4 + 1;
                int i2 = i * 4 + 2;
                int i3 = i * 4 + 3;

                vertices[i0] = v - rt - up;
                vertices[i1] = v + rt - up;
                vertices[i2] = v - rt + up;
                vertices[i3] = v + rt + up;

                uvs[i0] = uv0;
                uvs[i1] = uv1;
                uvs[i2] = uv2;
                uvs[i3] = uv3;

                Color c = Starmap.GetColorFromColorIndex(stars[i].colorIndex);
                if (magnitudeAffectsAlpha)
                {
                    c.a = Starmap.GetScaleFromMagnitude(stars[i].magnitude);
                }
                colors[i0] = colors[i1] = colors[i2] = colors[i3] = c;

                triangles[i * 6 + 0] = i0;
                triangles[i * 6 + 1] = i2;
                triangles[i * 6 + 2] = i1;
                triangles[i * 6 + 3] = i1;
                triangles[i * 6 + 4] = i2;
                triangles[i * 6 + 5] = i3;
            }

            m.vertices  = vertices;
            m.colors    = colors;
            m.uv        = uvs;
            m.triangles = triangles;

            m.RecalculateBounds();

            //m.bounds = new Bounds(
            //new Vector3(0, 0, 0),
            //new Vector3(distance * 2, distance * 2, distance * 2));

            return(m);
        }