private static ToolResult CopyUsedTexturesObj(string objFile, string outputDirectory, string textureDirectory) { bool success = false; string message = ""; ObjData objData = ObjParser.TryParseObj(objFile); if (objData != null) { objData.UpdateMtlData(); MtlData mtlData = objData.Mtl; if (mtlData != null) { success = ObjModifier.CopyUsedTextures(mtlData, outputDirectory, textureDirectory); message = MessageBoxConstants.GetMessageExecutionGeneric(success); } else { message = MessageBoxConstants.MessageErrorCopyTextures + MessageBoxConstants.MessageMtlNotFound; } } else { message = MessageBoxConstants.GetMessageExecutionErrorParse(objFile); } return(new ToolResult(message, success)); }
private static ToolResult ConvertObjToSmd(string objFile, string smdOutput, bool useTextureName) { bool success = false; string message = ""; ObjData objData = ObjParser.TryParseObj(objFile); if (objData != null) { objData.UpdateMtlData(); MtlData mtlData = objData.Mtl; if (mtlData == null) { // No MTL means the SMD will use a default material name for all objects useTextureName = false; } success = SmdExporter.WriteSmd(objData, mtlData, smdOutput, useTextureName); message = MessageBoxConstants.GetMessageExecutionCreation(success, smdOutput); } else { message = MessageBoxConstants.GetMessageExecutionErrorParse(objFile); } return(new ToolResult(message, success)); }
private static ToolResult DeleteUnusedMaterialsObj(string objFile, string objOutput) { bool success = false; string message = ""; ObjData objData = ObjParser.TryParseObj(objFile); if (objData != null) { objData.UpdateMtlData(); MtlData mtlData = objData.Mtl; if (mtlData != null) { ObjModifier.DeleteUnusedMaterials(objData, mtlData); success = ObjExporter.WriteObj(objData, mtlData, objOutput, makeMtl: true, useExistingMtl: true); message = MessageBoxConstants.GetMessageExecutionCreation(success, objOutput); } else { message = MessageBoxConstants.MessageErrorDeleteUnusedMaterials + MessageBoxConstants.MessageMtlNotFound; } } else { message = MessageBoxConstants.GetMessageExecutionErrorParse(objFile); } return(new ToolResult(message, success)); }
private static ToolResult DeleteMaterialsObj(string objFile, string objOutput) { bool success = false; string message = ""; ObjData objData = ObjParser.TryParseObj(objFile); if (objData != null) { ObjModifier.DeleteMaterials(objData); success = ObjExporter.WriteObj(objData, null, objOutput, makeMtl: false, useExistingMtl: false); message = MessageBoxConstants.GetMessageExecutionCreation(success, objOutput); } else { message = MessageBoxConstants.GetMessageExecutionErrorParse(objFile); } return(new ToolResult(message, success)); }
private static ToolResult ConvertRefModelSmd(string objFile, string smdOutput, Dictionary <string, string> inputs) { bool success = false; bool warn = false; StringBuilder sb = new StringBuilder(); ObjData objData = ObjParser.TryParseObj(objFile); if (objData != null) { // Delete all materials ObjModifier.DeleteMaterials(objData); // Scale the model by the given value if (inputs.TryGetValue(DictConstants.ScaleValue, out string scaleStr)) { if (Double.TryParse(scaleStr, out double scaleValue)) { ObjModifier.UniformScale(objData, scaleValue); // Scale Model } else { warn = true; sb.AppendLine(MessageBoxConstants.MessageErrorScale + MessageBoxConstants.MessageInvalidScaleValue); } } // The SMD will use a default material name for all objects success = SmdExporter.WriteSmd(objData, null, smdOutput, false); sb.Append(MessageBoxConstants.GetMessageExecutionCreation(success, smdOutput)); } else { sb.Append(MessageBoxConstants.GetMessageExecutionErrorParse(objFile)); } return(new ToolResult(sb.ToString(), success, warn)); }
private static ToolResult ModifyObj(string objFile, string objOutput, ObjOptions objOptions, Dictionary <string, string> inputs) { bool success = false; bool warn = false; StringBuilder sb = new StringBuilder(); ObjData objData = ObjParser.TryParseObj(objFile); if (objData != null) { objData.UpdateMtlData(); MtlData mtlData = objData.Mtl; if (objOptions.HasFlag(ObjOptions.BlackList)) { // Delete Blacklisted Objects first if (mtlData != null) { if (!ObjModifier.TryDeleteMatchingGroups(objData, mtlData, texturesList)) { warn = true; sb.AppendLine(MessageBoxConstants.MessageErrorDeleteBlackList + MessageBoxConstants.MessageErrorExecution); } } else { warn = true; sb.AppendLine(MessageBoxConstants.MessageErrorDeleteBlackList + MessageBoxConstants.MessageMtlNotFound); } } ObjModifier.CalculateNormal(objData); if (objOptions.HasFlag(ObjOptions.UniformScale)) { if (inputs.TryGetValue(DictConstants.ScaleValue, out string scaleStr)) { if (Double.TryParse(scaleStr, out double scaleValue)) { ObjModifier.UniformScale(objData, scaleValue); // Scale Model } else { warn = true; sb.AppendLine(MessageBoxConstants.MessageErrorScale + MessageBoxConstants.MessageInvalidScaleValue); } } } if (objOptions.HasFlag(ObjOptions.NonUniformScale)) { bool isScaleValueX = false; bool isScaleValueY = false; bool isScaleValueZ = false; double scaleValueX = 0.0; double scaleValueY = 0.0; double scaleValueZ = 0.0; if (inputs.TryGetValue(DictConstants.ScaleValueX, out string scaleStr)) { isScaleValueX = Double.TryParse(scaleStr, out scaleValueX); } if (inputs.TryGetValue(DictConstants.ScaleValueY, out scaleStr)) { isScaleValueY = Double.TryParse(scaleStr, out scaleValueY); } if (inputs.TryGetValue(DictConstants.ScaleValueZ, out scaleStr)) { isScaleValueZ = Double.TryParse(scaleStr, out scaleValueZ); } if (isScaleValueX && isScaleValueY && isScaleValueZ) { // Scale Model ObjModifier.NonUniformScale(objData, scaleValueX, scaleValueY, scaleValueZ); } else { warn = true; sb.AppendLine(MessageBoxConstants.MessageErrorScale + MessageBoxConstants.MessageInvalidScaleValues); } } if (objOptions.HasFlag(ObjOptions.Rotate)) { bool isRotateValueX = false; bool isRotateValueY = false; bool isRotateValueZ = false; double rotateValueX = 0.0; double rotateValueY = 0.0; double rotateValueZ = 0.0; if (inputs.TryGetValue(DictConstants.RotateValueX, out string rotationStr)) { isRotateValueX = Double.TryParse(rotationStr, out rotateValueX); } if (inputs.TryGetValue(DictConstants.RotateValueY, out rotationStr)) { isRotateValueY = Double.TryParse(rotationStr, out rotateValueY); } if (inputs.TryGetValue(DictConstants.RotateValueZ, out rotationStr)) { isRotateValueZ = Double.TryParse(rotationStr, out rotateValueZ); } if (isRotateValueX && isRotateValueY && isRotateValueZ) { // Rotate Model ObjModifier.RotateModel(objData, rotateValueX, rotateValueY, rotateValueZ); } else { warn = true; sb.AppendLine(MessageBoxConstants.MessageErrorRotate + MessageBoxConstants.MessageInvalidRotateValues); } } if (objOptions.HasFlag(ObjOptions.ReverseVertex)) { // Reverse Vertex Order ObjModifier.ReverseVertexOrder(objData); } if (objOptions.HasFlag(ObjOptions.Merge)) { if (mtlData != null) { // Merge groups and materials ObjModifier.MergeGroups(objData, mtlData); } else { warn = true; sb.AppendLine(MessageBoxConstants.MessageErrorMergeGroups + MessageBoxConstants.MessageMtlNotFound); } } if (objOptions.HasFlag(ObjOptions.Sort)) { // Sort groups if (!ObjModifier.SortGroups(objData)) { warn = true; sb.AppendLine(MessageBoxConstants.MessageErrorSortGroups + MessageBoxConstants.MessageInvalidGroupName); } if (mtlData != null) { // Sort materials if (!ObjModifier.SortMaterials(mtlData)) { warn = true; sb.AppendLine(MessageBoxConstants.MessageErrorSortMaterials + MessageBoxConstants.MessageInvalidMaterialName); } } else { warn = true; sb.AppendLine(MessageBoxConstants.MessageErrorSortMaterials + MessageBoxConstants.MessageMtlNotFound); } } success = ObjExporter.WriteObj(objData, mtlData, objOutput, makeMtl: true, useExistingMtl: true); sb.Append(MessageBoxConstants.GetMessageExecutionCreation(success, objOutput)); } else { sb.Append(MessageBoxConstants.GetMessageExecutionErrorParse(objFile)); } return(new ToolResult(sb.ToString(), success, warn)); }