forked from codeclubab/WOM-Converter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added -forcemats and -matreport options
- Loading branch information
Showing
3 changed files
with
252 additions
and
185 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,128 +1,160 @@ | ||
package com.wurmonline.womconverter; | ||
|
||
import java.io.File; | ||
import javafx.application.Application; | ||
import javafx.stage.FileChooser; | ||
import javafx.stage.Stage; | ||
import com.wurmonline.womconverter.converters.AssimpToWOMConverter; | ||
import java.io.IOException; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
|
||
|
||
public class Main extends Application { | ||
|
||
public static void main(String[] args) { | ||
if (args.length == 0 || (args.length == 1 && args[0].equalsIgnoreCase("-h"))) { | ||
System.out.println("Usage:"); | ||
System.out.println("java -jar WOM_Converter.jar [-generatetangents] [-recursive] [-indir input_directory] [-outdir output_directory] input_files_regex"); | ||
System.out.println("Options:"); | ||
System.out.println("-generatetangents : automatically generate tangent and binormal values if they aren't present in input files. Default: off."); | ||
System.out.println("-recursive : export files recursively in all subfolders relative to input directory, will create output directory folders accordingly. Default: off."); | ||
System.out.println("-indir input_directory : look for input files in input_directory. Must be a directory. Default: current dir."); | ||
System.out.println("-outdir output_directory : output directory for output files. Must be a directory. Default: current dir."); | ||
System.out.println("input_files_regex : regex used to lookup the input files to convert."); | ||
System.out.println("Examples:"); | ||
System.out.println("java -jar WOM_Converter.jar -generatetangents .+dae"); | ||
System.out.println("Will take all dae files in current directory, convert them to WOM generating tangent and binormal values when needed and export to current directory"); | ||
System.out.println("java -jar WOM_Converter.jar -devfilechooser"); | ||
System.out.println("Will skip normal program execution and ignore other options, opening file manager to quickly test exporting of single model"); | ||
|
||
launch(args); | ||
} | ||
|
||
boolean generateTangents = false; | ||
boolean recursive = false; | ||
String inputDirectory = ""; | ||
String outputDirectory = ""; | ||
|
||
for (int i = 0; i < args.length; i++) { | ||
String arg = args[i]; | ||
|
||
switch (arg) { | ||
case "-devfilechooser": | ||
launch(args); | ||
break; | ||
case "-generatetangents": | ||
generateTangents = true; | ||
break; | ||
case "-recursive": | ||
recursive = true; | ||
break; | ||
case "-indir": | ||
i++; | ||
inputDirectory = args[i]; | ||
break; | ||
case "-outdir": | ||
i++; | ||
outputDirectory = args[i]; | ||
break; | ||
} | ||
} | ||
|
||
String inputRegex = args[args.length - 1]; | ||
|
||
File inputDirectoryFile = new File(inputDirectory); | ||
if (!inputDirectoryFile.isDirectory()) { | ||
System.err.println("Input directory is not a valid directory: " + inputDirectory); | ||
return; | ||
} | ||
File outputDirectoryFile = new File(outputDirectory); | ||
if (!outputDirectoryFile.isDirectory()) { | ||
System.err.println("Output directory is not a valid directory: " + outputDirectory); | ||
return; | ||
} | ||
|
||
try { | ||
convertFiles(inputDirectoryFile, outputDirectoryFile, inputRegex, recursive, generateTangents); | ||
} catch (IOException ex) { | ||
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); | ||
} | ||
|
||
System.exit(0); | ||
} | ||
|
||
private static void convertFiles(File inputDirectory, File outputDirectory, String inputRegex, boolean recursive, boolean generateTangents) throws IOException { | ||
File[] filteredFiles = inputDirectory.listFiles((File file) -> { | ||
if (file.isDirectory()) { | ||
return false; | ||
} | ||
|
||
return file.getName().matches(inputRegex); | ||
}); | ||
|
||
for (File file : filteredFiles) { | ||
AssimpToWOMConverter.convert(file, outputDirectory, generateTangents); | ||
} | ||
|
||
if (recursive) { | ||
File[] directories = inputDirectory.listFiles((File file) -> { | ||
return file.isDirectory(); | ||
}); | ||
|
||
for (File directory : directories) { | ||
String name = directory.getName(); | ||
|
||
File newInputDirectory = directory; | ||
File newOutputDirectory = new File(outputDirectory, name); | ||
convertFiles(newInputDirectory, newOutputDirectory, inputRegex, recursive, generateTangents); | ||
} | ||
} | ||
} | ||
|
||
public void start(Stage primaryStage) throws Exception { | ||
FileChooser fileChooser = new FileChooser(); | ||
fileChooser.setTitle("Open Collada Model"); | ||
|
||
File modelFile = fileChooser.showOpenDialog(primaryStage); | ||
|
||
if (modelFile == null) { | ||
System.exit(0); | ||
} | ||
|
||
AssimpToWOMConverter.convert(modelFile, modelFile.getParentFile(), true); | ||
|
||
System.exit(0); | ||
} | ||
|
||
} | ||
package com.wurmonline.womconverter; | ||
|
||
import com.wurmonline.womconverter.converters.AssimpToWOMConverter; | ||
import javafx.application.Application; | ||
import javafx.stage.FileChooser; | ||
import javafx.stage.Stage; | ||
|
||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.IOException; | ||
import java.io.PrintStream; | ||
import java.util.Properties; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
|
||
|
||
public class Main extends Application { | ||
|
||
public static void main(String[] args) { | ||
if (args.length == 0 || (args.length == 1 && args[0].equalsIgnoreCase("-h"))) { | ||
System.out.println("Usage:"); | ||
System.out.println("java -jar WOM_Converter.jar [-generatetangents] [-recursive] [-indir input_directory] [-outdir output_directory] input_files_regex"); | ||
System.out.println("Options:"); | ||
System.out.println("-generatetangents : automatically generate tangent and binormal values if they aren't present in input files. Default: off."); | ||
System.out.println("-recursive : export files recursively in all subfolders relative to input directory, will create output directory folders accordingly. Default: off."); | ||
System.out.println("-indir input_directory : look for input files in input_directory. Must be a directory. Default: current dir."); | ||
System.out.println("-outdir output_directory : output directory for output files. Must be a directory. Default: current dir."); | ||
System.out.println("-matreport <file> : reports materials and textures used in each model to given file"); | ||
System.out.println("-forcemats <file> : load overrides for material names based on texture file"); | ||
System.out.println("input_files_regex : regex used to lookup the input files to convert."); | ||
System.out.println("Examples:"); | ||
System.out.println("java -jar WOM_Converter.jar -generatetangents .+dae"); | ||
System.out.println("Will take all dae files in current directory, convert them to WOM generating tangent and binormal values when needed and export to current directory"); | ||
System.out.println("java -jar WOM_Converter.jar -devfilechooser"); | ||
System.out.println("Will skip normal program execution and ignore other options, opening file manager to quickly test exporting of single model"); | ||
|
||
launch(args); | ||
} | ||
|
||
boolean generateTangents = false; | ||
boolean recursive = false; | ||
String inputDirectory = ""; | ||
String outputDirectory = ""; | ||
File forceMatsFile = null; | ||
File matReportFile = null; | ||
|
||
for (int i = 0; i < args.length; i++) { | ||
String arg = args[i]; | ||
|
||
switch (arg) { | ||
case "-devfilechooser": | ||
launch(args); | ||
break; | ||
case "-generatetangents": | ||
generateTangents = true; | ||
break; | ||
case "-recursive": | ||
recursive = true; | ||
break; | ||
case "-indir": | ||
i++; | ||
inputDirectory = args[i]; | ||
break; | ||
case "-outdir": | ||
i++; | ||
outputDirectory = args[i]; | ||
break; | ||
case "-forcemats": | ||
i++; | ||
forceMatsFile = new File(args[i]); | ||
break; | ||
case "-matreport": | ||
i++; | ||
matReportFile = new File(args[i]); | ||
break; | ||
} | ||
} | ||
|
||
String inputRegex = args[args.length - 1]; | ||
|
||
File inputDirectoryFile = new File(inputDirectory); | ||
if (!inputDirectoryFile.isDirectory()) { | ||
System.err.println("Input directory is not a valid directory: " + inputDirectory); | ||
return; | ||
} | ||
File outputDirectoryFile = new File(outputDirectory); | ||
if (!outputDirectoryFile.isDirectory()) { | ||
System.err.println("Output directory is not a valid directory: " + outputDirectory); | ||
return; | ||
} | ||
|
||
Properties forceMats = new Properties(); | ||
if (forceMatsFile != null) { | ||
try (FileInputStream in = new FileInputStream(forceMatsFile)) { | ||
forceMats.load(in); | ||
} catch (IOException e) { | ||
throw new RuntimeException("Error reading forcemats file", e); | ||
} | ||
} | ||
|
||
MatReporter matReport = null; | ||
|
||
try { | ||
if (matReportFile != null) { | ||
matReport = new MatReporter(matReportFile); | ||
} | ||
convertFiles(inputDirectoryFile, outputDirectoryFile, inputRegex, recursive, generateTangents, forceMats, matReport); | ||
} catch (IOException ex) { | ||
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); | ||
} finally { | ||
if (matReport != null) matReport.close(); | ||
} | ||
|
||
System.exit(0); | ||
} | ||
|
||
private static void convertFiles(File inputDirectory, File outputDirectory, String inputRegex, boolean recursive, boolean generateTangents, Properties forceMats, MatReporter matReport) throws IOException { | ||
File[] filteredFiles = inputDirectory.listFiles((File file) -> { | ||
if (file.isDirectory()) { | ||
return false; | ||
} | ||
|
||
return file.getName().matches(inputRegex); | ||
}); | ||
|
||
for (File file : filteredFiles) { | ||
AssimpToWOMConverter.convert(file, outputDirectory, generateTangents, forceMats, matReport); | ||
} | ||
|
||
if (recursive) { | ||
File[] directories = inputDirectory.listFiles((File file) -> { | ||
return file.isDirectory(); | ||
}); | ||
|
||
for (File directory : directories) { | ||
String name = directory.getName(); | ||
|
||
File newInputDirectory = directory; | ||
File newOutputDirectory = new File(outputDirectory, name); | ||
convertFiles(newInputDirectory, newOutputDirectory, inputRegex, recursive, generateTangents, forceMats, matReport); | ||
} | ||
} | ||
} | ||
|
||
public void start(Stage primaryStage) throws Exception { | ||
FileChooser fileChooser = new FileChooser(); | ||
fileChooser.setTitle("Open Collada Model"); | ||
|
||
File modelFile = fileChooser.showOpenDialog(primaryStage); | ||
|
||
if (modelFile == null) { | ||
System.exit(0); | ||
} | ||
|
||
AssimpToWOMConverter.convert(modelFile, modelFile.getParentFile(), true, new Properties(), null); | ||
|
||
System.exit(0); | ||
} | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/com/wurmonline/womconverter/MatReporter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.wurmonline.womconverter; | ||
|
||
import java.io.File; | ||
import java.io.FileNotFoundException; | ||
import java.io.PrintStream; | ||
import java.util.HashMap; | ||
|
||
public class MatReporter implements AutoCloseable { | ||
private PrintStream output; | ||
private HashMap<String, String> mats = new HashMap<>(); | ||
|
||
public MatReporter(File outFile) { | ||
try { | ||
output = new PrintStream(outFile); | ||
} catch (FileNotFoundException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
public void addMat(String mat, String file) { | ||
mats.put(mat, file); | ||
} | ||
|
||
public void reportFile(String file) { | ||
output.println(file); | ||
mats.forEach((m, f) -> output.println(String.format("- %s -> %s", m, f))); | ||
mats.clear(); | ||
} | ||
|
||
@Override | ||
public void close() { | ||
output.close(); | ||
} | ||
} |
Oops, something went wrong.