Skip to content

Commit

Permalink
Merge pull request #1499 from 1445643474/config_params
Browse files Browse the repository at this point in the history
set command parameters
  • Loading branch information
legobadman authored Nov 2, 2023
2 parents 53645cd + 5e15718 commit 50bbce0
Show file tree
Hide file tree
Showing 33 changed files with 1,019 additions and 22 deletions.
12 changes: 11 additions & 1 deletion ui/zenoedit/dock/ztabdockwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "panel/zenoproppanel.h"
#include "../panel/zenospreadsheet.h"
#include "../panel/zlogpanel.h"
#include "../panel/zenocommandparamspanel.h"
#include "viewport/viewportwidget.h"
#include "viewport/displaywidget.h"
#include "nodesview/zenographseditor.h"
Expand Down Expand Up @@ -223,6 +224,10 @@ QWidget* ZTabDockWidget::createTabWidget(PANEL_TYPE type)
wid->initUI();
return wid;
}
case PANEL_COMMAND_PARAMS:
{
return new ZenoCommandParamsPanel;
}
}
return nullptr;
}
Expand All @@ -239,6 +244,7 @@ QString ZTabDockWidget::type2Title(PANEL_TYPE type)
case PANEL_LIGHT: return tr("Light");
case PANEL_OPTIX_VIEW: return tr("Optix");
case PANEL_IMAGE: return tr("Image");
case PANEL_COMMAND_PARAMS: return tr("Command Params");
default:
return "";
}
Expand Down Expand Up @@ -271,6 +277,9 @@ PANEL_TYPE ZTabDockWidget::title2Type(const QString& title)
else if (title == tr("Optix")|| title == "Optix") {
type = PANEL_OPTIX_VIEW;
}
else if (title == tr("Command Params") || title == "Command Params") {
type = PANEL_COMMAND_PARAMS;
}
return type;
}

Expand Down Expand Up @@ -522,7 +531,7 @@ void ZTabDockWidget::onAddTabClicked()
font.setBold(false);
menu->setFont(font);

static QList<QString> panels = { tr("Parameter"), tr("Scene Viewport"), tr("Node Editor"), tr("Spreadsheet"), tr("Log"), tr("Image"), tr("Optix") };
static QList<QString> panels = { tr("Parameter"), tr("Scene Viewport"), tr("Node Editor"), tr("Spreadsheet"), tr("Log"), tr("Image"), tr("Optix"), tr("Command Params") };
for (QString name : panels)
{
QAction* pAction = new QAction(name);
Expand All @@ -549,6 +558,7 @@ void ZTabDockWidget::onAddTabClicked()
case 5: m_debugPanel = PANEL_LIGHT; break;
case 6: m_debugPanel = PANEL_IMAGE; break;
case 7: m_debugPanel = PANEL_OPTIX_VIEW; break;
case 8: m_debugPanel = PANEL_COMMAND_PARAMS; break;
}
m_tabWidget->setCurrentIndex(idx);
}
Expand Down
3 changes: 2 additions & 1 deletion ui/zenoedit/dock/ztabdockwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ enum PANEL_TYPE
PANEL_LOG,
PANEL_LIGHT,
PANEL_IMAGE,
PANEL_OPTIX_VIEW
PANEL_OPTIX_VIEW,
PANEL_COMMAND_PARAMS
};

class ZTabDockWidget : public QDockWidget
Expand Down
2 changes: 1 addition & 1 deletion ui/zenoedit/launch/corelaunch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ void launchProgram(IGraphsModel* pModel, LAUNCH_PARAM param)
JsonArrayBatch batch(writer);
JsonHelper::AddVariantList({"setBeginFrameNumber", param.beginFrame}, "int", writer);
JsonHelper::AddVariantList({"setEndFrameNumber", param.endFrame}, "int", writer);
serializeScene(pModel, writer, param.applyLightAndCameraOnly, param.applyMaterialOnly);
serializeScene(pModel, writer, param.applyLightAndCameraOnly, param.applyMaterialOnly, param.paramPath);
}
std::string progJson(s.GetString());
#ifdef DEBUG_SERIALIZE
Expand Down
1 change: 1 addition & 0 deletions ui/zenoedit/launch/corelaunch.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ struct LAUNCH_PARAM {
bool autoCleanCacheInCacheRoot = true; //auto remove cachedir in cache root
QString zsgPath;
int projectFps = 24;
QString paramPath;
};

void launchProgram(IGraphsModel *pModel, LAUNCH_PARAM param);
Expand Down
1 change: 1 addition & 0 deletions ui/zenoedit/launch/optixcmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ int optixcmd(const QCoreApplication& app, int port)
{"subzsg", "subgraphzsg", "subgraph zsg file path"},
{"cacheautorm", "cacheautoremove", "remove cache after render"},
{"optixShowBackground", "optixShowBackground", "optix record with background"},
{"paramsPath", "paramsPath", "paramsPath"},
});
cmdParser.process(app);

Expand Down
59 changes: 53 additions & 6 deletions ui/zenoedit/launch/serialize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,29 @@ static void getOptStr(const QString& sockType, QVariant& defl, QString& opStr)
}
}

static void serializeGraph(IGraphsModel* pGraphsModel, const QModelIndex& subgIdx, QString const &graphIdPrefix, bool bView, RAPIDJSON_WRITER& writer, bool bNestedSubg = true, bool applyLightAndCameraOnly = false, bool applyMaterialOnly = false)
static void serializeGraph(IGraphsModel* pGraphsModel, const QModelIndex& subgIdx, QString const &graphIdPrefix, bool bView, RAPIDJSON_WRITER& writer, bool bNestedSubg = true, bool applyLightAndCameraOnly = false, bool applyMaterialOnly = false, const QString &configPath = "")
{
ZASSERT_EXIT(pGraphsModel && subgIdx.isValid());

rapidjson::Document configDoc;
if (!configPath.isEmpty())
{
QFile file(configPath);
bool ret = file.open(QIODevice::ReadOnly | QIODevice::Text);
if (!ret) {
zeno::log_error("cannot open config file: {} ({})", configPath.toStdString(),
file.errorString().toStdString());
}

QByteArray bytes = file.readAll();
configDoc.Parse(bytes);

if (!configDoc.IsObject())
{
zeno::log_error("config file is corrupted");
}
}

//scan all the nodes in the subgraph.
for (int i = 0; i < pGraphsModel->itemCount(subgIdx); i++)
{
Expand Down Expand Up @@ -158,7 +177,7 @@ static void serializeGraph(IGraphsModel* pGraphsModel, const QModelIndex& subgId
AddStringList({"pushSubnetScope", ident}, writer);
const QString& prefix = nameMangling(graphIdPrefix, idx.data(ROLE_OBJID).toString());
bool _bView = bView && (idx.data(ROLE_OPTIONS).toInt() & OPT_VIEW);
serializeGraph(pGraphsModel, pGraphsModel->index(name), prefix, _bView, writer, true, applyLightAndCameraOnly);
serializeGraph(pGraphsModel, pGraphsModel->index(name), prefix, _bView, writer, true, applyLightAndCameraOnly, applyMaterialOnly, configPath);
AddStringList({"popSubnetScope", ident}, writer);
}
}
Expand Down Expand Up @@ -272,8 +291,23 @@ static void serializeGraph(IGraphsModel* pGraphsModel, const QModelIndex& subgId
}
}

QVariant defl = inSockIdx.data(ROLE_PARAM_VALUE);
const QString& sockType = inSockIdx.data(ROLE_PARAM_TYPE).toString();
const FuckQMap<QString, CommandParam>& commandParams = pGraphsModel->commandParams();
QVariant defl = inSockIdx.data(ROLE_PARAM_VALUE);

//command params
const QString& objPath = inSockIdx.data(ROLE_OBJPATH).toString();
if (!configPath.isEmpty() && commandParams.contains(objPath))
{
const QString& command = commandParams[objPath].name;
if (configDoc.HasMember(command.toUtf8()))
{
const auto& obj = configDoc[command.toStdString().c_str()];
if (obj.IsObject() && obj.HasMember("value"))
defl = UiHelper::parseJsonByType(sockType, obj["value"], nullptr);
}
}

QString opStr = "setNodeInput";
getOptStr(sockType, defl, opStr);
if (opStr == "setNodeInput") {
Expand Down Expand Up @@ -312,7 +346,20 @@ static void serializeGraph(IGraphsModel* pGraphsModel, const QModelIndex& subgId
QString opStr = "setNodeParam";
getOptStr(param_info.typeDesc, param_info.value, opStr);
if (opStr == "setNodeParam") {
paramValue = UiHelper::parseVarByType(param_info.typeDesc, param_info.value, nullptr);
const FuckQMap<QString, CommandParam>& commandParams = pGraphsModel->commandParams();
//command params
const QString& objPath = param_info.paramPath;
QString command = commandParams[objPath].name;
if (!configPath.isEmpty() && commandParams.contains(objPath) && configDoc.HasMember(command.toUtf8()))
{
const auto& obj = configDoc[command.toStdString().c_str()];
if (obj.IsObject() && obj.HasMember("value"))
paramValue = UiHelper::parseJsonByType(param_info.typeDesc, obj["value"], nullptr);
}
else
{
paramValue = UiHelper::parseVarByType(param_info.typeDesc, param_info.value, nullptr);
}
}
else {
//formula/keyframe
Expand Down Expand Up @@ -383,9 +430,9 @@ static void serializeGraph(IGraphsModel* pGraphsModel, const QModelIndex& subgId
}
}

void serializeScene(IGraphsModel* pModel, RAPIDJSON_WRITER& writer, bool applyLightAndCameraOnly, bool applyMaterialOnly)
void serializeScene(IGraphsModel* pModel, RAPIDJSON_WRITER& writer, bool applyLightAndCameraOnly, bool applyMaterialOnly, const QString& configPath)
{
serializeGraph(pModel, pModel->index("main"), "", true, writer, true, applyLightAndCameraOnly, applyMaterialOnly);
serializeGraph(pModel, pModel->index("main"), "", true, writer, true, applyLightAndCameraOnly, applyMaterialOnly, configPath);
}

static void serializeSceneOneGraph(IGraphsModel* pModel, RAPIDJSON_WRITER& writer, QString subgName)
Expand Down
2 changes: 1 addition & 1 deletion ui/zenoedit/launch/serialize.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class IGraphsModel;

void serializeScene(IGraphsModel* pModel, RAPIDJSON_WRITER& writer, bool applyLightAndCameraOnly = false, bool applyMaterialOnly = false);
void serializeScene(IGraphsModel* pModel, RAPIDJSON_WRITER& writer, bool applyLightAndCameraOnly = false, bool applyMaterialOnly = false, const QString& configPath = "");
QString serializeSceneCpp(IGraphsModel* pModel);

#endif
Loading

0 comments on commit 50bbce0

Please sign in to comment.