From d2f202de5cea5e4d33b78a0d14f73a2389efe6f4 Mon Sep 17 00:00:00 2001 From: Raimund58 Date: Tue, 11 Mar 2025 15:48:36 +0000 Subject: [PATCH] Feat: Use custom color config --- .../com/sheepit/client/rendering/Job.java | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/sheepit/client/rendering/Job.java b/src/main/java/com/sheepit/client/rendering/Job.java index 40391cd..7c20601 100644 --- a/src/main/java/com/sheepit/client/rendering/Job.java +++ b/src/main/java/com/sheepit/client/rendering/Job.java @@ -40,6 +40,9 @@ import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.io.StringWriter; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; @@ -200,7 +203,7 @@ import static com.sheepit.client.rendering.RenderSettings.UPDATE_METHOD_BY_TILE; new_env.put("BLENDER_SYSTEM_DATAFILES", ""); new_env.put("BLENDER_SYSTEM_PYTHON", ""); - new_env.put("OCIO", ""); //prevent blender from loading a non-standard color configuration + new_env.put("OCIO", getColorConfig()); //load custom color configs. If the path is invalid, Blender should fall back to the bundled config new_env.put("TEMP", configuration.getWorkingDirectory().getAbsolutePath().replace("\\", "\\\\")); new_env.put("TMP", configuration.getWorkingDirectory().getAbsolutePath().replace("\\", "\\\\")); @@ -658,6 +661,26 @@ import static com.sheepit.client.rendering.RenderSettings.UPDATE_METHOD_BY_TILE; return Error.Type.OK; } + /** + * Checks whether the project contains a custom color config and if so, returns the path to it, otherwise returns an empty string. + * The color config must be in a folder called OCIO and contain a config.ocio file + */ + private String getColorConfig() { + String scenePath = getScenePath(); // Get the full path to the .blend file + String sceneDirectory = new File(scenePath).getParent(); // Get the directory containing the .blend file + + Path ocioPath = Paths.get(sceneDirectory, "OCIO", "config.ocio"); // Construct the correct path to the custom color config + + if (Files.exists(ocioPath)) { + log.info("Job::getColorConfig Using custom color configuration"); + return ocioPath.toAbsolutePath().toString(); + } + else { + log.info("Job::getColorConfig Using default color configuration"); + return ""; + } + } + private int computeRenderingProgress(String line, Pattern tilePattern, int currentProgress) { Matcher standardTileInfo = tilePattern.matcher(line); int newProgress = currentProgress;