These add a gradle task to convert all .blend files in your assets folder to .blend.glb files (in folder)
It works by calling a powershell file as a gradle task.
The powershell file enumerates the folder and checks if the generated file needs updating.
This calls the blender.exe with a background task and the python script on each file.
Task in gradle:
task convertBlendFiles(type: Exec) {
workingDir 'src/assets'
//sorry windows only unless you install powershell on linux
commandLine 'cmd', '/c', 'Powershell -File blend2gltf.ps1'
}
I haven’t thought about it but can you call ProcessBuilder? Seems like you should be able to, not sure but then linux users could use it without installing anything.
Not sure about this either but gradle should be able to determine if your on windows or not so you could just call the proper command.
private static final boolean IS_WINDOWS = System.getProperty("os.name")
.toLowerCase().startsWith("windows");
Been doing this myself so was curious.
//Specify which type of command to send
if (IS_WINDOWS) {
//Windows shell
cmd.add("cmd.exe");
//Run Command and then terminate
cmd.add("/c");
//Shows shell instead of running in background
// cmd.add("start");
//Path to updater script from registry
cmd.add(updaterPref.get("startscript", null));
} else {
//Bourne shell
cmd.add("sh");
//Read from string
cmd.add("-c");
//TODO Setup registry on linux
//Path to updater start script from registry
cmd.add("./Updater/bin/Updater");
}
For Linux cmd won’t work, but you could also just execute the blenderCommand directly and don’t echo text but use println (but then I guess you need to inline the exec {} statement.
The weird echo calls are because or an error: execCommand == null.
Its also an issue that the gradle type: Exec looked like it isn’t designed to run multiple commandline calls.
But i get the complaint 'C:\Program' is not recognized as an internal or external command, so its not quoting it correctly for me. There isn’t enough examples of this in gradle that i can find .
But at least i don’t need the random echo commands anymore, thanks.
If any one gets this to run on linux, ill figure something out with the is_windows stuff and put it together.
That is strange, for background:
Usually there are two ways to define/execute a command
“shell=true”: You pass everything as one giant string and the OS does the escaping etc. This is considered harmful, specifically if the user could pass arbitrary values.
array of parameters (much like String[] args), where you’d pass every argument and stuff as one (that’s what you did above).