예제 #1
0
        public override void AddTriangles(RenderInfo info, ArrayList <VertexNormalColor> opaqueVertexData, ArrayList <VertexNormalColor> transparentVertexData)
        {
            if (vertexList == null)
            {
                CreateMesh();
            }

            Matrix4x4 mat = GetTransform();

            if (PrimitiveColor.A < 255)
            {
                for (int i = 0; i < vertexList.Count; i++)
                {
                    VertexNormalColor newVertex = mat * vertexList[i];
                    newVertex.Color = PrimitiveColor;
                    transparentVertexData.Add(newVertex);
                }
            }
            else
            {
                for (int i = 0; i < vertexList.Count; i++)
                {
                    VertexNormalColor newVertex = mat * vertexList[i];
                    newVertex.Color = PrimitiveColor;
                    opaqueVertexData.Add(newVertex);
                }
            }
        }
예제 #2
0
        private void CreateMesh()
        {
            double height = 0.5;
            double radius = 0.5;

            Segments = SMath.Clamp(Segments, 3, 256);

            VertexList = new VertexNormalColor[Segments * (CreateCaps ? 2 : 1) + 1];
            IndexList  = new uint[Segments * 3 + (CreateCaps ? (Segments - 2) * 3 : 0)];

            // Create vertices
            VertexList[0].Position = new Vector3(0, 0, height);
            for (int i = 0; i < Segments; i++)
            {
                double  angle            = ((double)i / (double)Segments) * Math.PI * 2.0;
                Vector2 planarCoordinate = Vector2.FromAngle(angle, radius);

                VertexList[i + 1].Position = new Vector3(planarCoordinate.X, planarCoordinate.Y, -height);

                if (CreateCaps)
                {
                    // Top (for cap)
                    VertexList[i + Segments + 1].Position = new Vector3(planarCoordinate.X, planarCoordinate.Y, -height);
                }
            }

            // Create normals
            Vector3 capNormal = CreateCaps ? GeometryMath.GetTriangleNormal(VertexList[1].Position, VertexList[2].Position, VertexList[3].Position) : new Vector3(0, 0, 0);

            for (int i = 0; i < Segments; i++)
            {
                Vector3 manifoldNormal = GeometryMath.GetTriangleNormal(VertexList[0].Position, VertexList[(i + 1) % Segments + 1].Position, VertexList[i + 1].Position);
                VertexList[i + 1].Normal = manifoldNormal;
                if (CreateCaps)
                {
                    VertexList[Segments + i + 1].Normal = capNormal;
                }
            }

            // Create triangles
            int index = 0;

            for (int i = 0; i < Segments; i++)
            {
                // Manifold
                IndexList[index++] = 0;
                IndexList[index++] = (uint)((i + 1) % Segments + 1);
                IndexList[index++] = (uint)(i + 1);

                if (CreateCaps && i < Segments - 2)
                {
                    // Cap
                    IndexList[index++] = (uint)(Segments + 1);
                    IndexList[index++] = (uint)(Segments + i + 2);
                    IndexList[index++] = (uint)(Segments + i + 3);
                }
            }
        }
예제 #3
0
        public override void AddTriangles(RenderInfo info, ArrayList <VertexNormalColor> opaqueVertexData, ArrayList <VertexNormalColor> transparentVertexData, ArrayList <uint> opaqueIndexData, ArrayList <uint> transparentIndexData)
        {
            if (VertexList == null || IndexList == null)
            {
                CreateMesh();
            }

            Matrix4x4 mat = GetTransform();

            if (PrimitiveColor.A < 255)
            {
                int baseIndex = transparentVertexData.Count;

                for (int i = 0; i < VertexList.Length; i++)
                {
                    VertexNormalColor newVertex = mat * VertexList[i];
                    newVertex.Color = PrimitiveColor;
                    transparentVertexData.Add(newVertex);
                }

                for (int i = 0; i < IndexList.Length; i++)
                {
                    transparentIndexData.Add((uint)(IndexList[i] + baseIndex));
                }
            }
            else
            {
                int baseIndex = opaqueVertexData.Count;

                for (int i = 0; i < VertexList.Length; i++)
                {
                    VertexNormalColor newVertex = mat * VertexList[i];
                    newVertex.Color = PrimitiveColor;
                    opaqueVertexData.Add(newVertex);
                }

                for (int i = 0; i < IndexList.Length; i++)
                {
                    opaqueIndexData.Add((uint)(IndexList[i] + baseIndex));
                }
            }
        }
예제 #4
0
        private void CreateMesh()
        {
            double height       = 0.5;
            double TopRadius    = 0.5;
            double BottomRadius = TopRadius * BottomRadiusScale;

            Segments = SMath.Clamp(Segments, 3, 256);

            VertexList = new VertexNormalColor[Segments * (CreateCaps ? 4 : 2)];
            IndexList  = new uint[Segments * 6 + (CreateCaps ? (Segments - 1) * 6 : 0)];

            // Create vertices
            for (int i = 0; i < Segments; i++)
            {
                double  angle            = ((double)i / (double)Segments) * Math.PI * 2.0;
                Vector2 planarCoordinate = Vector2.FromAngle(angle, 1.0);
                // Top
                VertexList[i + Segments * 0].Position = new Vector3(planarCoordinate.X * TopRadius, planarCoordinate.Y * TopRadius, height);
                // Bottom
                VertexList[i + Segments * 1].Position = new Vector3(planarCoordinate.X * BottomRadius, planarCoordinate.Y * BottomRadius, -height);

                if (CreateCaps)
                {
                    // Top (for cap)
                    VertexList[i + Segments * 2].Position = new Vector3(planarCoordinate.X * TopRadius, planarCoordinate.Y * TopRadius, height);
                    // Bottom (for cap)
                    VertexList[i + Segments * 3].Position = new Vector3(planarCoordinate.X * BottomRadius, planarCoordinate.Y * BottomRadius, -height);
                }
            }

            // Create normals
            Vector3 topNormal    = CreateCaps ? GeometryMath.GetTriangleNormal(VertexList[Segments * 2].Position, VertexList[Segments * 2 + 2].Position, VertexList[Segments * 2 + 1].Position) : new Vector3(0, 0, 0);
            Vector3 bottomNormal = CreateCaps ? GeometryMath.GetTriangleNormal(VertexList[Segments * 3].Position, VertexList[Segments * 3 + 1].Position, VertexList[Segments * 3 + 2].Position) : new Vector3(0, 0, 0);

            for (int i = 0; i < Segments; i++)
            {
                Vector3 manifoldNormal = GeometryMath.GetTriangleNormal(VertexList[i].Position, VertexList[(i + 1) % Segments].Position, VertexList[i + Segments].Position);
                VertexList[Segments * 0 + i].Normal = manifoldNormal;
                VertexList[Segments * 1 + i].Normal = manifoldNormal;
                if (CreateCaps)
                {
                    VertexList[Segments * 2 + i].Normal = topNormal;
                    VertexList[Segments * 3 + i].Normal = bottomNormal;
                }
            }

            // Create triangles
            int index = 0;

            for (int i = 0; i < Segments; i++)
            {
                // Manifold
                IndexList[index++] = (uint)i;
                IndexList[index++] = (uint)((i + 1) % Segments);
                IndexList[index++] = (uint)(i + Segments);

                IndexList[index++] = (uint)((i + 1) % Segments);
                IndexList[index++] = (uint)((i + 1) % Segments + Segments);
                IndexList[index++] = (uint)(i + Segments);

                if (CreateCaps && i < Segments - 1)
                {
                    // Top cap
                    IndexList[index++] = (uint)(Segments * 2);
                    IndexList[index++] = (uint)(Segments * 2 + i + 1);
                    IndexList[index++] = (uint)(Segments * 2 + i);

                    // Bottom cap
                    IndexList[index++] = (uint)(Segments * 3);
                    IndexList[index++] = (uint)(Segments * 3 + i);
                    IndexList[index++] = (uint)(Segments * 3 + i + 1);
                }
            }
        }