Change parameter format of blender-render command

This commit is contained in:
Sybren A. Stüvel 2022-01-28 14:48:19 +01:00
parent 30518ca3af
commit 0b3311b0a7
6 changed files with 38 additions and 28 deletions

View File

@ -63,8 +63,9 @@ type AuthoredTask struct {
type AuthoredCommand struct {
Type string
Parameters map[string]string
Parameters AuthoredCommandParameters
}
type AuthoredCommandParameters map[string]interface{}
func (a *Author) Task(name string, taskType string) (*AuthoredTask, error) {
at := AuthoredTask{
@ -77,7 +78,7 @@ func (a *Author) Task(name string, taskType string) (*AuthoredTask, error) {
return &at, nil
}
func (a *Author) Command(cmdType string, parameters map[string]string) (*AuthoredCommand, error) {
func (a *Author) Command(cmdType string, parameters AuthoredCommandParameters) (*AuthoredCommand, error) {
ac := AuthoredCommand{cmdType, parameters}
return &ac, nil
}

View File

@ -104,12 +104,17 @@ func TestSimpleBlenderRenderHappy(t *testing.T) {
// Tasks should have been created to render the frames.
assert.Equal(t, 4, len(aj.Tasks))
t0 := aj.Tasks[0]
expectCliArgs := []interface{}{ // They are strings, but Goja doesn't know that and will produce an []interface{}.
"--render-output", "/render/sf__intermediate-2006-01-02_090405/frames",
"--render-format", settings["format"].(string),
"--render-frame", "1-3",
}
assert.Equal(t, "render-1-3", t0.Name)
assert.Equal(t, 1, len(t0.Commands))
assert.Equal(t, "blender-render", t0.Commands[0].Type)
assert.Equal(t, "{blender}", t0.Commands[0].Parameters["cmd"])
assert.Equal(t, settings["filepath"], t0.Commands[0].Parameters["filepath"])
assert.Equal(t, settings["format"], t0.Commands[0].Parameters["format"])
assert.Equal(t, "1-3", t0.Commands[0].Parameters["frames"])
assert.Equal(t, "/render/sf__intermediate-2006-01-02_090405/frames", t0.Commands[0].Parameters["render_output"])
assert.EqualValues(t, AuthoredCommandParameters{
"exe": "{blender}",
"blendfile": settings["filepath"].(string),
"args": expectCliArgs,
}, t0.Commands[0].Parameters)
}

View File

@ -91,11 +91,13 @@ function authorRenderTasks(settings, renderDir, renderOutput) {
for (let chunk of chunks) {
const task = author.Task(`render-${chunk}`, "blender");
const command = author.Command("blender-render", {
cmd: settings.blender_cmd,
filepath: settings.filepath,
format: settings.format,
render_output: path.join(renderDir, path.basename(renderOutput)),
frames: chunk,
exe: settings.blender_cmd,
blendfile: settings.filepath,
args: [
"--render-output", path.join(renderDir, path.basename(renderOutput)),
"--render-format", settings.format,
"--render-frame", chunk,
]
});
task.addCommand(command);
renderTasks.push(task);

View File

@ -78,7 +78,7 @@ func (db *DB) StoreJob(ctx context.Context, authoredJob job_compilers.AuthoredJo
Name: authoredJob.Name,
JobType: authoredJob.JobType,
Priority: int8(authoredJob.Priority),
Settings: JobSettings(authoredJob.Settings),
Settings: StringInterfaceMap(authoredJob.Settings),
Metadata: StringStringMap(authoredJob.Metadata),
}
@ -91,7 +91,7 @@ func (db *DB) StoreJob(ctx context.Context, authoredJob job_compilers.AuthoredJo
for _, authoredCommand := range authoredTask.Commands {
commands = append(commands, Command{
Type: authoredCommand.Type,
Parameters: authoredCommand.Parameters,
Parameters: StringInterfaceMap(authoredCommand.Parameters),
})
}

View File

@ -73,12 +73,14 @@ func TestStoreAuthoredJob(t *testing.T) {
Commands: []job_compilers.AuthoredCommand{
{
Type: "blender-render",
Parameters: StringStringMap{
"cmd": "{blender}",
"filepath": "/path/to/file.blend",
"format": "PNG",
"render_output": "/path/to/output/######.png",
"frames": "1-3",
Parameters: job_compilers.AuthoredCommandParameters{
"exe": "{blender}",
"blendfile": "/path/to/file.blend",
"args": []interface{}{
"--render-output", "/path/to/output/######.png",
"--render-format", "PNG",
"--render-frame", "1-3",
},
}},
},
}
@ -93,7 +95,7 @@ func TestStoreAuthoredJob(t *testing.T) {
Commands: []job_compilers.AuthoredCommand{
{
Type: "merge-frames-to-video",
Parameters: StringStringMap{
Parameters: job_compilers.AuthoredCommandParameters{
"images": "/path/to/output/######.png",
"output": "/path/to/output/preview.mkv",
"ffmpegParams": "-c:v hevc -crf 31",

View File

@ -37,11 +37,11 @@ type Job struct {
Priority int8 `gorm:"type:smallint;not null"`
Status string `gorm:"type:varchar(32);not null"` // See JobStatusXxxx consts in openapi_types.gen.go
Settings JobSettings `gorm:"type:jsonb"`
Settings StringInterfaceMap `gorm:"type:jsonb"`
Metadata StringStringMap `gorm:"type:jsonb"`
}
type JobSettings map[string]interface{}
type StringInterfaceMap map[string]interface{}
type StringStringMap map[string]string
type Task struct {
@ -66,7 +66,7 @@ type Commands []Command
type Command struct {
Type string `json:"type"`
Parameters StringStringMap `json:"parameters"`
Parameters StringInterfaceMap `json:"parameters"`
}
func (c Commands) Value() (driver.Value, error) {
@ -80,10 +80,10 @@ func (c *Commands) Scan(value interface{}) error {
return json.Unmarshal(b, &c)
}
func (js JobSettings) Value() (driver.Value, error) {
func (js StringInterfaceMap) Value() (driver.Value, error) {
return json.Marshal(js)
}
func (js *JobSettings) Scan(value interface{}) error {
func (js *StringInterfaceMap) Scan(value interface{}) error {
b, ok := value.([]byte)
if !ok {
return errors.New("type assertion to []byte failed")