Exemple #1
0
        public static void AddMesh <TMaterial, TvG, TvM, TvS>(this MeshBuilder <TMaterial, TvG, TvM, TvS> meshBuilder, Mesh srcMesh, Converter <Material, TMaterial> materialFunc)
            where TvG : struct, IVertexGeometry
            where TvM : struct, IVertexMaterial
            where TvS : struct, IVertexSkinning
        {
            Guard.NotNull(meshBuilder, nameof(meshBuilder));
            Guard.NotNull(materialFunc, nameof(materialFunc));

            if (srcMesh == null)
            {
                return;
            }

            var materialMap = srcMesh.Primitives
                              .Select(prim => prim.Material)
                              .Distinct()
                              .ToDictionary(mat => mat, mat => materialFunc(mat));

            Material currMat = null;
            PrimitiveBuilder <TMaterial, TvG, TvM, TvS> currPrim = null;

            foreach (var tri in srcMesh.EvaluateTriangles <TvG, TvM, TvS>())
            {
                if (currMat != tri.Material)
                {
                    currMat  = tri.Material;
                    currPrim = meshBuilder.UsePrimitive(materialMap[currMat]);
                }

                currPrim.AddTriangle(tri.A, tri.B, tri.C);
            }
        }
Exemple #2
0
 private void ExportPrimitive(SurfaceBody surfaceBody, Face surfaceFace, PrimitiveBuilder <MaterialBuilder, VertexPositionNormal, VertexEmpty, VertexEmpty> primitive)
 {
     try
     {
         int facetCount;
         int vertCount;
         var coords  = new double[] { };
         var norms   = new double[] { };
         var indices = new int[] { };
         if (surfaceBody != null)
         {
             surfaceBody.CalculateFacets((double)exportTolerance, out vertCount, out facetCount, out coords, out norms, out indices);
         }
         else
         {
             surfaceFace.CalculateFacets((double)exportTolerance, out vertCount, out facetCount, out coords, out norms, out indices);
         }
         if (indices.Length % 3 != 0 || coords.Length % 3 != 0)
         {
             warnings.Add("Invalid mesh calculated!");
             return;
         }
         for (var c = 0; c < indices.Length; c += 3)
         {
             var indexA = indices[c];
             var indexB = indices[c + 1];
             var indexC = indices[c + 2];
             primitive.AddTriangle(
                 GetNormsAndCoords(coords, norms, indexA - 1),
                 GetNormsAndCoords(coords, norms, indexB - 1),
                 GetNormsAndCoords(coords, norms, indexC - 1)
                 );
         }
     }
     catch
     {
         warnings.Add("Unable to export surface body");
     }
 }