Merge branch 'feat/disable_viewport' into 'master'

Add script to disable the viewport.

See merge request sheepitrenderfarm/client!207
This commit is contained in:
harlekin
2023-03-27 15:39:09 +00:00

View File

@@ -202,6 +202,7 @@ import java.util.regex.Pattern;
}
core_script += ignore_signal_script;
File disableViewportScript = null;
File script_file = null;
String[] command1 = getRendererCommand().split(" ");
int size_command = command1.length + 2; // + 2 for script
@@ -230,11 +231,62 @@ import java.util.regex.Pattern;
for (String arg : command1) {
switch (arg) {
case ".c":
command.add("-P");
try {
disableViewportScript = File.createTempFile("optimize_viewport_script_", ".py", configuration.getWorkingDirectory());
File file = new File(disableViewportScript.getAbsolutePath());
FileWriter fwriter;
fwriter = new FileWriter(file);
PrintWriter out = new PrintWriter(fwriter);
out.write("import bpy");
out.write("\n");
out.write("from bpy.app.handlers import persistent");
out.write("\n");
out.write("@persistent");
out.write("\n");
out.write("def hide_stuff(dummy):");
out.write("\n");
out.write("#Hide collections in the viewport");
out.write("\n");
out.write(" for col in bpy.data.collections:");
out.write("\n");
out.write("\n col.hide_viewport = True");
out.write("\n");
out.write(" for obj in bpy.data.objects:");
out.write("\n");
out.write(" #Hide objects in the viewport");
out.write("\n");
out.write(" obj.hide_viewport = True");
out.write("\n");
out.write(" #Hide modifier in the viewport");
out.write("\n");
out.write(" for mod in obj.modifiers:");
out.write("\n");
out.write(" mod.show_viewport = False");
out.write("\n");
out.write("bpy.app.handlers.version_update.append(hide_stuff)");
out.write("\n");
out.close();
command.add(disableViewportScript.getAbsolutePath());
}
catch (IOException e) {
StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw));
for (String logline : configuration.filesystemHealthCheck()) {
log.debug(logline);
}
log.error("Job::render exception on script generation, will return UNKNOWN " + e + " stacktrace " + sw.toString());
return Error.Type.UNKNOWN;
}
command.add(getScenePath());
command.add("-P");
try {
script_file = File.createTempFile("script_", "", configuration.getWorkingDirectory());
script_file = File.createTempFile("script_", ".py", configuration.getWorkingDirectory());
File file = new File(script_file.getAbsolutePath());
FileWriter txt;
txt = new FileWriter(file);
@@ -391,6 +443,9 @@ import java.util.regex.Pattern;
if (script_file != null) {
script_file.delete();
}
if (disableViewportScript != null) {
disableViewportScript.delete();
}
// Once the process is finished (either finished successfully or with an error) move back to
// base icon (isolated S with no progress bar)
@@ -406,7 +461,9 @@ import java.util.regex.Pattern;
if (script_file != null) {
script_file.delete();
}
if (disableViewportScript != null) {
disableViewportScript.delete();
}
if (process.getRenderDuration() == -1) {
if (timeStamp == null) {
timeStamp = new Date(process.getStartTime()).toInstant();
@@ -467,6 +524,9 @@ import java.util.regex.Pattern;
if (script_file != null) {
script_file.delete();
}
if (disableViewportScript != null) {
disableViewportScript.delete();
}
StringWriter sw = new StringWriter();
err.printStackTrace(new PrintWriter(sw));
for (String logline : configuration.filesystemHealthCheck()) {
@@ -485,7 +545,9 @@ import java.util.regex.Pattern;
if (script_file != null) {
script_file.delete();
}
if (disableViewportScript != null) {
disableViewportScript.delete();
}
// find the picture file
final String filename_without_extension = getPrefixOutputImage() + getFrameNumber();