public static IEnumerable <(IVertexBuilder A, IVertexBuilder B, IVertexBuilder C, Material Material)> EvaluateTriangles(this MeshPrimitive prim, MESHXFORM xform = null)
        {
            if (prim == null)
            {
                yield break;
            }
            if (xform != null && !xform.Visible)
            {
                yield break;
            }

            var triangles = prim.GetTriangleIndices();

            if (!triangles.Any())
            {
                yield break;
            }

            var vertices = prim.GetVertexColumns(xform);
            var vtype    = vertices.GetCompatibleVertexType();

            foreach (var t in triangles)
            {
                var a = vertices.GetVertex(vtype, t.A);
                var b = vertices.GetVertex(vtype, t.B);
                var c = vertices.GetVertex(vtype, t.C);

                yield return(a, b, c, prim.Material);
            }
        }
Exemple #2
0
        public static IEnumerable <(IVertexBuilder A, IVertexBuilder B, IVertexBuilder C, Material Material)> EvaluateTriangles(this MeshPrimitive prim, MESHXFORM xform = null)
        {
            if (prim == null)
            {
                yield break;
            }
            if (xform != null && !xform.Visible)
            {
                yield break;
            }

            var vertices  = prim.GetVertexColumns();
            var triangles = prim.GetTriangleIndices();

            if (!triangles.Any())
            {
                yield break;
            }

            foreach (var xinst in Transforms.InstancingTransform.Evaluate(xform))
            {
                var xvertices = xinst != null?vertices.WithTransform(xinst) : vertices;

                var vtype = vertices.GetCompatibleVertexType();

                foreach (var(ta, tb, tc) in triangles)
                {
                    var va = xvertices.GetVertex(vtype, ta);
                    var vb = xvertices.GetVertex(vtype, tb);
                    var vc = xvertices.GetVertex(vtype, tc);

                    yield return(va, vb, vc, prim.Material);
                }
            }
        }