From 57a6d7479ba42728ca20f216c873bffbe2e47c53 Mon Sep 17 00:00:00 2001 From: Lino Schmidt Date: Wed, 23 Nov 2022 19:47:28 +0100 Subject: [PATCH] settings get to blender per console --- dependencies/blenderScript.py | 71 +++++++++++++---------------- src/components/blenderController.ts | 44 ++++++++++++++---- 2 files changed, 67 insertions(+), 48 deletions(-) diff --git a/dependencies/blenderScript.py b/dependencies/blenderScript.py index 64a39d4..3555d90 100644 --- a/dependencies/blenderScript.py +++ b/dependencies/blenderScript.py @@ -5,10 +5,7 @@ import math import sys import time import bpy -import xml.etree.ElementTree as ET - -argv = sys.argv -argv = argv[argv.index("--") + 1:] +import json logger = logging.getLogger('simple_example') logger.setLevel(logging.INFO) @@ -43,28 +40,22 @@ def _map(x, in_min, in_max, out_min, out_max): logger.info("Blender started successfully!") while True: - command = input("Waiting for command: ") + command = input("Waiting for command: ").split(" -- ") time.sleep(0.5) - settingsRoot = ET.parse(argv[0]+"/settings.xml").getroot() + settings = json.loads(command[1]) - StickMode = settingsRoot[3].text - if(StickMode == "true"): - StickMode = 2 - else: - StickMode = 1 + stickMode2 = settings["stickMode2"] + width = settings["width"] + stickDistance = _map(settings["stickDistance"], 0, 100, 5, 105) + fps = settings["fps"] + videoFormat = settings["videoFormat"] + logs = settings["logs"][1:][:-1].split("\"\"") + output = settings["output"] + dataPath = settings["dataPath"] - width = int(settingsRoot[1].text) - StickDistance = _map(int(settingsRoot[2].text), 0, 100, 5, 105) - - if(command == "startRendering"): - - fps = int(settingsRoot[0].text) - videoFormat = settingsRoot[4].text - logs = settingsRoot[5].text[1:][:-1].split("\"\"") - output = settingsRoot[6].text - + if(command[0] == "startRendering"): logCount = len(logs) logNumber = 1 @@ -129,13 +120,13 @@ while True: bpy.context.scene.render.image_settings.color_mode = 'RGBA' scn.render.resolution_x = width - GimbalCoverR.location[0] = StickDistance - GimbalR.location[0] = StickDistance - TrailR.location[0] = StickDistance - Plane.location[0] = StickDistance - Camera.location[0] = StickDistance/2 - Camera.data.ortho_scale = StickDistance+5 - scn.render.resolution_y = int(width/_map(StickDistance, 5, 105, 2, 21.6)) + GimbalCoverR.location[0] = stickDistance + GimbalR.location[0] = stickDistance + TrailR.location[0] = stickDistance + Plane.location[0] = stickDistance + Camera.location[0] = stickDistance/2 + Camera.data.ortho_scale = stickDistance+5 + scn.render.resolution_y = int(width/_map(stickDistance, 5, 105, 2, 21.6)) bpy.context.scene.render.filepath = output + "\\" + log.split("/")[-1].split("\\")[-1].replace(".csv", "."+videoFormat) scn.render.fps = 1000 @@ -168,7 +159,7 @@ while True: StickR.rotation_euler=[0,0,0] GimbalR.rotation_euler=[0,0,0] - if StickMode == "1": + if stickMode2 == False: StickL.rotation_euler.rotate_axis("Y", ailP) GimbalL.rotation_euler.rotate_axis("X", eleP) StickR.rotation_euler.rotate_axis("Y", rudP) @@ -194,19 +185,19 @@ while True: logNumber+=1 - elif(command == "getRender"): + elif(command[0] == "getRender"): bpy.context.scene.render.image_settings.file_format = 'PNG' - bpy.context.scene.render.filepath = argv[0] + "\\render.png" + bpy.context.scene.render.filepath = dataPath + "\\render.png" scn.render.resolution_x = width - GimbalCoverR.location[0] = StickDistance - GimbalR.location[0] = StickDistance - TrailR.location[0] = StickDistance - Plane.location[0] = StickDistance - Camera.location[0] = StickDistance/2 - Camera.data.ortho_scale = StickDistance+5 - scn.render.resolution_y = int(width/_map(StickDistance, 5, 105, 2, 21.6)) + GimbalCoverR.location[0] = stickDistance + GimbalR.location[0] = stickDistance + TrailR.location[0] = stickDistance + Plane.location[0] = stickDistance + Camera.location[0] = stickDistance/2 + Camera.data.ortho_scale = stickDistance+5 + scn.render.resolution_y = int(width/_map(stickDistance, 5, 105, 2, 21.6)) bpy.context.scene.frame_set(0) @@ -215,7 +206,7 @@ while True: StickR.rotation_euler=[0,0,0] GimbalR.rotation_euler=[0,0,0] - if(StickMode == 2): + if(stickMode2 == True): StickL.rotation_euler.rotate_axis("Y", 0) GimbalL.rotation_euler.rotate_axis("X", 0.436) StickR.rotation_euler.rotate_axis("Y", 0) @@ -238,7 +229,7 @@ while True: StickR.rotation_euler=[0,0,0] GimbalR.rotation_euler=[0,0,0] - if(StickMode == 2): + if(stickMode2 == True): StickL.rotation_euler.rotate_axis("Y", 0) GimbalL.rotation_euler.rotate_axis("X", 0.436) StickR.rotation_euler.rotate_axis("Y", 0) diff --git a/src/components/blenderController.ts b/src/components/blenderController.ts index 398265c..77fa940 100644 --- a/src/components/blenderController.ts +++ b/src/components/blenderController.ts @@ -1,10 +1,10 @@ -import { blenderPath, blenderScriptPath, dataPath, templatePath, finsishedIconPath } from "./paths"; +import { blenderPath, blenderScriptPath, templatePath, finsishedIconPath, dataPath } from "./paths"; import {spawn} from "child_process"; import logger from "./logger"; import { setBlenderLoading, setBlenderStatus } from "./ui/menu"; import { setLogNumber, setPastTime, setRemainingTime, setRenderDisplayProgress, setStatus, setPastTimeNow, setRemainingTimeNow } from "./ui/renderingPage"; import {imageLoading, imageLoaded} from "./ui/settingsPage"; -import { getLogSize, getInOutSettings } from "./settings"; +import { getLogSize, getInOutSettings, getActiveProfile } from "./settings"; import isValid from "is-valid-path"; import { pageSetRendering, setProgress, openPage, Page } from "../renderer"; import { ipcRenderer } from "electron"; @@ -20,9 +20,7 @@ const blenderStartString = [ templatePath, "--background", "--python", - blenderScriptPath, - "--", - dataPath.replaceAll("\\", "/") + blenderScriptPath ] let blenderConsole = spawn(blenderPath, blenderStartString).on('error', function(err) { @@ -158,7 +156,17 @@ function startBlender() { } else { waitingForRender = false; renderingPicture = true; - blenderConsole.stdin.write("getRender\n"); + const blenderArgs = JSON.stringify({ + stickMode2:getActiveProfile().stickMode2, + width:getActiveProfile().width, + stickDistance:getActiveProfile().stickDistance, + fps:getActiveProfile().fps, + videoFormat:getActiveProfile().videoFormat, + logs:getInOutSettings().log, + output:getInOutSettings().output, + dataPath:dataPath + }); + blenderConsole.stdin.write("getRender -- "+blenderArgs+"\n"); setBlenderStatus("Rendering"); setBlenderLoading(true); imageLoading(); @@ -192,7 +200,17 @@ function blender(command:blenderCmd) { imageLoading(); setBlenderStatus("Rendering"); setBlenderLoading(true); - blenderConsole.stdin.write("getRender\n"); + const blenderArgs = JSON.stringify({ + stickMode2:getActiveProfile().stickMode2, + width:getActiveProfile().width, + stickDistance:getActiveProfile().stickDistance, + fps:getActiveProfile().fps, + videoFormat:getActiveProfile().videoFormat, + logs:getInOutSettings().log, + output:getInOutSettings().output, + dataPath:dataPath + }); + blenderConsole.stdin.write("getRender -- "+blenderArgs+"\n"); } else { waitingForRender = true; } @@ -225,7 +243,17 @@ function blender(command:blenderCmd) { pageSetRendering(true); setBlenderStatus("Rendering"); setBlenderLoading(true); - blenderConsole.stdin.write("startRendering\n"); + const blenderArgs = JSON.stringify({ + stickMode2:getActiveProfile().stickMode2, + width:getActiveProfile().width, + stickDistance:getActiveProfile().stickDistance, + fps:getActiveProfile().fps, + videoFormat:getActiveProfile().videoFormat, + logs:getInOutSettings().log, + output:getInOutSettings().output, + dataPath:dataPath + }); + blenderConsole.stdin.write("startRendering -- "+blenderArgs+"\n"); renderInfo.startTime = new Date().getTime(); setPastTime("0min 0sec");