Example #1
0
        protected override void BuildMesh(Mesh mesh, int starIndex, int starCount)
        {
            var positions = new Vector3[starCount * 4];
            var colors    = new Color[starCount * 4];
            var coords1   = new Vector2[starCount * 4];
            var indices   = new int[starCount * 6];
            var minMaxSet = false;
            var min       = default(Vector3);
            var max       = default(Vector3);

            for (var i = 0; i < starCount; i++)
            {
                NextQuad(ref SgtBackdropQuad.Temp, starIndex + i);

                var offV     = i * 4;
                var offI     = i * 6;
                var radius   = SgtBackdropQuad.Temp.Radius;
                var uv       = tempCoords[SgtHelper.Mod(SgtBackdropQuad.Temp.Variant, tempCoords.Count)];
                var rotation = Quaternion.FromToRotation(Vector3.back, SgtBackdropQuad.Temp.Position) * Quaternion.Euler(0.0f, 0.0f, SgtBackdropQuad.Temp.Angle);
                var up       = rotation * Vector3.up * radius;
                var right    = rotation * Vector3.right * radius;

                ExpandBounds(ref minMaxSet, ref min, ref max, SgtBackdropQuad.Temp.Position, radius);

                positions[offV + 0] = SgtBackdropQuad.Temp.Position - up - right;
                positions[offV + 1] = SgtBackdropQuad.Temp.Position - up + right;
                positions[offV + 2] = SgtBackdropQuad.Temp.Position + up - right;
                positions[offV + 3] = SgtBackdropQuad.Temp.Position + up + right;

                colors[offV + 0]             =
                    colors[offV + 1]         =
                        colors[offV + 2]     =
                            colors[offV + 3] = SgtBackdropQuad.Temp.Color;

                coords1[offV + 0] = new Vector2(uv.x, uv.y);
                coords1[offV + 1] = new Vector2(uv.z, uv.y);
                coords1[offV + 2] = new Vector2(uv.x, uv.w);
                coords1[offV + 3] = new Vector2(uv.z, uv.w);

                indices[offI + 0] = offV + 0;
                indices[offI + 1] = offV + 1;
                indices[offI + 2] = offV + 2;
                indices[offI + 3] = offV + 3;
                indices[offI + 4] = offV + 2;
                indices[offI + 5] = offV + 1;
            }

            mesh.vertices  = positions;
            mesh.colors    = colors;
            mesh.uv        = coords1;
            mesh.triangles = indices;
            mesh.bounds    = SgtHelper.NewBoundsFromMinMax(min, max);
        }
Example #2
0
        protected override void BuildMesh(Mesh mesh, int starIndex, int starCount)
        {
            var positions = new Vector3[starCount * 4];
            var colors    = new Color[starCount * 4];
            var normals   = new Vector3[starCount * 4];
            var tangents  = new Vector4[starCount * 4];
            var coords1   = new Vector2[starCount * 4];
            var coords2   = new Vector2[starCount * 4];
            var indices   = new int[starCount * 6];
            var minMaxSet = false;
            var min       = default(Vector3);
            var max       = default(Vector3);

            for (var i = 0; i < starCount; i++)
            {
                NextQuad(ref SgtStarfieldStar.Temp, starIndex + i);

                var offV     = i * 4;
                var offI     = i * 6;
                var position = SgtStarfieldStar.Temp.Position;
                var radius   = SgtStarfieldStar.Temp.Radius;
                var angle    = Mathf.Repeat(SgtStarfieldStar.Temp.Angle / 180.0f, 2.0f) - 1.0f;
                var uv       = tempCoords[SgtHelper.Mod(SgtStarfieldStar.Temp.Variant, tempCoords.Count)];

                ExpandBounds(ref minMaxSet, ref min, ref max, position, radius);

                positions[offV + 0]             =
                    positions[offV + 1]         =
                        positions[offV + 2]     =
                            positions[offV + 3] = position;

                colors[offV + 0]             =
                    colors[offV + 1]         =
                        colors[offV + 2]     =
                            colors[offV + 3] = SgtStarfieldStar.Temp.Color;

                normals[offV + 0] = new Vector3(-1.0f, 1.0f, angle);
                normals[offV + 1] = new Vector3(1.0f, 1.0f, angle);
                normals[offV + 2] = new Vector3(-1.0f, -1.0f, angle);
                normals[offV + 3] = new Vector3(1.0f, -1.0f, angle);

                tangents[offV + 0]             =
                    tangents[offV + 1]         =
                        tangents[offV + 2]     =
                            tangents[offV + 3] = new Vector4(SgtStarfieldStar.Temp.PulseOffset, SgtStarfieldStar.Temp.PulseSpeed, SgtStarfieldStar.Temp.PulseRange, 0.0f);

                coords1[offV + 0] = new Vector2(uv.x, uv.y);
                coords1[offV + 1] = new Vector2(uv.z, uv.y);
                coords1[offV + 2] = new Vector2(uv.x, uv.w);
                coords1[offV + 3] = new Vector2(uv.z, uv.w);

                coords2[offV + 0] = new Vector2(radius, 0.5f);
                coords2[offV + 1] = new Vector2(radius, -0.5f);
                coords2[offV + 2] = new Vector2(radius, 0.5f);
                coords2[offV + 3] = new Vector2(radius, -0.5f);

                indices[offI + 0] = offV + 0;
                indices[offI + 1] = offV + 1;
                indices[offI + 2] = offV + 2;
                indices[offI + 3] = offV + 3;
                indices[offI + 4] = offV + 2;
                indices[offI + 5] = offV + 1;
            }

            mesh.vertices  = positions;
            mesh.colors    = colors;
            mesh.normals   = normals;
            mesh.tangents  = tangents;
            mesh.uv        = coords1;
            mesh.uv2       = coords2;
            mesh.triangles = indices;
            mesh.bounds    = SgtHelper.NewBoundsFromMinMax(min, max);
        }
Example #3
0
        protected override void BuildMesh(Mesh mesh, int asteroidIndex, int asteroidCount)
        {
            var positions = new Vector3[asteroidCount * 4];
            var colors    = new Color[asteroidCount * 4];
            var normals   = new Vector3[asteroidCount * 4];
            var tangents  = new Vector4[asteroidCount * 4];
            var coords1   = new Vector2[asteroidCount * 4];
            var coords2   = new Vector2[asteroidCount * 4];
            var indices   = new int[asteroidCount * 6];
            var maxWidth  = 0.0f;
            var maxHeight = 0.0f;

            for (var i = 0; i < asteroidCount; i++)
            {
                NextQuad(ref SgtBeltAsteroid.Temp, asteroidIndex + i);

                var offV     = i * 4;
                var offI     = i * 6;
                var radius   = SgtBeltAsteroid.Temp.Radius;
                var distance = SgtBeltAsteroid.Temp.OrbitDistance;
                var height   = SgtBeltAsteroid.Temp.Height;
                var uv       = tempCoords[SgtHelper.Mod(SgtBeltAsteroid.Temp.Variant, tempCoords.Count)];

                maxWidth  = Mathf.Max(maxWidth, distance + radius);
                maxHeight = Mathf.Max(maxHeight, height + radius);

                positions[offV + 0]             =
                    positions[offV + 1]         =
                        positions[offV + 2]     =
                            positions[offV + 3] = new Vector3(SgtBeltAsteroid.Temp.OrbitAngle, distance, SgtBeltAsteroid.Temp.OrbitSpeed);

                colors[offV + 0]             =
                    colors[offV + 1]         =
                        colors[offV + 2]     =
                            colors[offV + 3] = SgtBeltAsteroid.Temp.Color;

                normals[offV + 0] = new Vector3(-1.0f, 1.0f, 0.0f);
                normals[offV + 1] = new Vector3(1.0f, 1.0f, 0.0f);
                normals[offV + 2] = new Vector3(-1.0f, -1.0f, 0.0f);
                normals[offV + 3] = new Vector3(1.0f, -1.0f, 0.0f);

                tangents[offV + 0]             =
                    tangents[offV + 1]         =
                        tangents[offV + 2]     =
                            tangents[offV + 3] = new Vector4(SgtBeltAsteroid.Temp.Angle / Mathf.PI, SgtBeltAsteroid.Temp.Spin / Mathf.PI, 0.0f, 0.0f);

                coords1[offV + 0] = new Vector2(uv.x, uv.y);
                coords1[offV + 1] = new Vector2(uv.z, uv.y);
                coords1[offV + 2] = new Vector2(uv.x, uv.w);
                coords1[offV + 3] = new Vector2(uv.z, uv.w);

                coords2[offV + 0]             =
                    coords2[offV + 1]         =
                        coords2[offV + 2]     =
                            coords2[offV + 3] = new Vector2(radius, height);

                indices[offI + 0] = offV + 0;
                indices[offI + 1] = offV + 1;
                indices[offI + 2] = offV + 2;
                indices[offI + 3] = offV + 3;
                indices[offI + 4] = offV + 2;
                indices[offI + 5] = offV + 1;
            }

            mesh.vertices  = positions;
            mesh.colors    = colors;
            mesh.normals   = normals;
            mesh.tangents  = tangents;
            mesh.uv        = coords1;
            mesh.uv2       = coords2;
            mesh.triangles = indices;
            mesh.bounds    = new Bounds(Vector3.zero, new Vector3(maxWidth * 2.0f, maxHeight * 2.0f, maxWidth * 2.0f));
        }
Example #4
0
        protected override void BuildMesh(Mesh mesh, int starIndex, int starCount)
        {
            var minMaxSet = false;
            var min       = default(Vector3);
            var max       = default(Vector3);

            SgtHelper.Resize(positions, starCount * 4);
            SgtHelper.Resize(colors32, starCount * 4);
            SgtHelper.Resize(coords1, starCount * 4);
            SgtHelper.Resize(coords2, starCount * 4);
            SgtHelper.Resize(indices, starCount * 6);

            for (var i = 0; i < starCount; i++)
            {
                NextQuad(ref SgtBackdropQuad.Temp, starIndex + i);

                var offV     = i * 4;
                var offI     = i * 6;
                var radius   = SgtBackdropQuad.Temp.Radius;
                var uv       = tempCoords[SgtHelper.Mod(SgtBackdropQuad.Temp.Variant, tempCoords.Count)];
                var rotation = Quaternion.FromToRotation(Vector3.back, SgtBackdropQuad.Temp.Position) * Quaternion.Euler(0.0f, 0.0f, SgtBackdropQuad.Temp.Angle);
                var up       = rotation * Vector3.up * radius;
                var right    = rotation * Vector3.right * radius;

                ExpandBounds(ref minMaxSet, ref min, ref max, SgtBackdropQuad.Temp.Position, radius);

                positions[offV + 0] = SgtBackdropQuad.Temp.Position - up - right;
                positions[offV + 1] = SgtBackdropQuad.Temp.Position - up + right;
                positions[offV + 2] = SgtBackdropQuad.Temp.Position + up - right;
                positions[offV + 3] = SgtBackdropQuad.Temp.Position + up + right;

                colors32[offV + 0]             =
                    colors32[offV + 1]         =
                        colors32[offV + 2]     =
                            colors32[offV + 3] = SgtBackdropQuad.Temp.Color;

                coords1[offV + 0] = new Vector2(uv.x, uv.y);
                coords1[offV + 1] = new Vector2(uv.z, uv.y);
                coords1[offV + 2] = new Vector2(uv.x, uv.w);
                coords1[offV + 3] = new Vector2(uv.z, uv.w);

                coords2[offV + 0]             =
                    coords2[offV + 1]         =
                        coords2[offV + 2]     =
                            coords2[offV + 3] = SgtBackdropQuad.Temp.Position;

                indices[offI + 0] = offV + 0;
                indices[offI + 1] = offV + 1;
                indices[offI + 2] = offV + 2;
                indices[offI + 3] = offV + 3;
                indices[offI + 4] = offV + 2;
                indices[offI + 5] = offV + 1;
            }

            mesh.SetVertices(positions);
            mesh.SetColors(colors32);
            mesh.SetUVs(0, coords1);
            mesh.SetUVs(1, coords2);
            mesh.SetTriangles(indices, 0, false);
            mesh.bounds = SgtHelper.NewBoundsFromMinMax(min, max);
        }