private static List <Node> CreateSurfaceMeshNodes(PartSurfaceMesh partSurface, Scene scene, string surfaceName, MeshExportOptions exportOptions) { var meshNodes = new List <Node>(); int materialIndex = scene.MaterialCount; scene.Materials.Add(new Material() { Name = $"{surfaceName}_Material" }); if (exportOptions.IndividualComponents) { int meshIndex = 0; foreach (var comp in partSurface.Mesh.Cullings) { string nodeName = $"{surfaceName}_Mesh{meshIndex++}"; var compModel = partSurface.Mesh.GetCullingGeometry(comp); var mNode = CreateMeshNode(scene, compModel, nodeName, materialIndex, exportOptions); meshNodes.Add(mNode); if (comp.ReplacementMesh != null && exportOptions.IncludeAltMeshes) { mNode = CreateMeshNode(scene, comp.ReplacementMesh, nodeName + "Alt", materialIndex, exportOptions); meshNodes.Add(mNode); } } } else { var mNode = CreateMeshNode(scene, partSurface.Mesh.Geometry, surfaceName, materialIndex, exportOptions); meshNodes.Add(mNode); } return(meshNodes); }
private void button1_Click(object sender, EventArgs e) { LDD.LDDEnvironment.Initialize(); if (!LDD.LDDEnvironment.IsInstalled) { return; } var meshFolder = LDD.LDDEnvironment.InstalledEnvironment.GetLddSubdirectory(LDD.LddDirectory.ApplicationData, "db\\Primitives\\LOD0"); var meshFiles = Directory.GetFiles(meshFolder, "*.g*"); progressBar1.Maximum = meshFiles.Length; Task.Factory.StartNew(() => { foreach (string meshFilePath in meshFiles) { //progressBar1.Value += 1; //Console.WriteLine($"Reading {Path.GetFileNameWithoutExtension(meshFilePath)}.."); string currentFile = Path.GetFileName(meshFilePath); var messages = new List <string>(); try { var mesh = LDD.Files.MeshFile.Read(meshFilePath); bool isDecorationFile = PartSurfaceMesh.ParseSurfaceID(meshFilePath) > 0; if (isDecorationFile != mesh.IsTextured) { messages.Add("\tInvalid decoration state! #1"); } foreach (var culling in mesh.Cullings) { if (culling.ReplacementMesh != null && culling.Type != MeshCullingType.FemaleStud) { messages.Add($"\tAlt mesh used for culling type {culling.Type} #2"); } //if (culling.Studs.Select(x => x.ConnectorIndex).Distinct().Count() > 1) // messages.Add($"\tMore than one Custom2DField reference! (NormalStuds) #3.1"); if (culling.AdjacentStuds.Select(x => x.ConnectorIndex).Distinct().Count() > 1) { messages.Add($"\tMore than one Custom2DField reference! (AdjacentStuds) #3.2"); } if (culling.Studs.Sum(x => x.FieldIndices.Count) > 1 && culling.Type == MeshCullingType.MaleStud) { messages.Add("\tMore than one field referenced for MaleStud #4.1"); } if (culling.AdjacentStuds.Count > 1 && culling.Type == MeshCullingType.BrickTube) { messages.Add("\tMore than one field referenced for BrickTube #4.2"); } if (culling.AdjacentStuds.Sum(x => x.FieldIndices.Count) > 0 && culling.Type != MeshCullingType.BrickTube) { messages.Add("\tAdjacent studs used for non BrickTube! #5"); } } } catch (Exception ex) { messages.Add($"Error reading file:\r\n{ex}"); } if (messages.Count > 0) { Console.WriteLine($"Issues with file: {currentFile}"); Console.WriteLine(string.Join("\r\n", messages)); //messages.ForEach(x => Console.WriteLine(x)); Console.WriteLine(string.Empty); } } }); }