matx-code-improvements #8

Merged
Bogdan Nagirniak merged 6 commits from BogdanNagirniak/blender:matx-code-improvements into matx-export-material 2023-09-04 10:10:09 +02:00
6 changed files with 39 additions and 39 deletions
Showing only changes of commit 46a1440702 - Show all commits

View File

@ -10,7 +10,7 @@ namespace blender::nodes::materialx {
NodeItem MathNodeParser::compute()
{
/* TODO: finish some math operations */
auto op = node->custom1;
auto op = node_->custom1;
NodeItem res = empty();
/* Single operand operations */
@ -158,7 +158,7 @@ NodeItem MathNodeParser::compute()
}
}
bool clamp_output = node->custom2 != 0;
bool clamp_output = node_->custom2 != 0;
if (clamp_output && res) {
res = res.clamp();
}

View File

@ -14,50 +14,50 @@ NodeParser::NodeParser(MaterialX::GraphElement *graph,
const Material *material,
const bNode *node,
const bNodeSocket *socket_out)
: graph(graph), depsgraph(depsgraph), material(material), node(node), socket_out(socket_out)
: graph_(graph), depsgraph_(depsgraph), material_(material), node_(node), socket_out_(socket_out)
{
}
NodeItem NodeParser::create_node(const std::string &mx_category, const std::string &mx_type)
{
NodeItem res = empty();
res.node = graph->addNode(mx_category, MaterialX::EMPTY_STRING, mx_type);
res.node = graph_->addNode(mx_category, MaterialX::EMPTY_STRING, mx_type);
return res;
}
NodeItem NodeParser::get_input_default(const std::string &name)
{
return get_input_default(node->input_by_identifier(name));
return get_input_default(node_->input_by_identifier(name));
}
NodeItem NodeParser::get_input_default(int index)
{
return get_input_default(node->input_socket(index));
return get_input_default(node_->input_socket(index));
}
NodeItem NodeParser::get_input_link(const std::string &name)
{
return get_input_link(node->input_by_identifier(name));
return get_input_link(node_->input_by_identifier(name));
}
NodeItem NodeParser::get_input_link(int index)
{
return get_input_link(node->input_socket(index));
return get_input_link(node_->input_socket(index));
}
NodeItem NodeParser::get_input_value(const std::string &name)
{
return get_input_value(node->input_by_identifier(name));
return get_input_value(node_->input_by_identifier(name));
}
NodeItem NodeParser::get_input_value(int index)
{
return get_input_value(node->input_socket(index));
return get_input_value(node_->input_socket(index));
}
NodeItem NodeParser::empty() const
{
return NodeItem(graph);
return NodeItem(graph_);
}
NodeItem NodeParser::get_input_default(const bNodeSocket &socket)
@ -108,7 +108,7 @@ NodeItem NodeParser::get_input_link(const bNodeSocket &socket)
/* Computing from_node with required NodeParser object */
#define CASE_NODE_TYPE(type, T) \
case type: \
res = T(graph, depsgraph, material, from_node, link->fromsock).compute_full(); \
res = T(graph_, depsgraph_, material_, from_node, link->fromsock).compute_full(); \
break;
switch (from_node->typeinfo->type) {
@ -143,12 +143,12 @@ NodeItem NodeParser::get_input_value(const bNodeSocket &socket)
NodeItem NodeParser::compute_full()
{
CLOG_INFO(LOG_MATERIALX_SHADER, 1, "%s [%d]", node->name, node->typeinfo->type);
CLOG_INFO(LOG_MATERIALX_SHADER, 1, "%s [%d]", node_->name, node_->typeinfo->type);
NodeItem res = compute();
if (res.node) {
res.set_name(node->output_sockets().size() == 1 ?
std::string(node->name) :
std::string(node->name) + "_" + socket_out->name);
res.set_name(node_->output_sockets().size() == 1 ?
std::string(node_->name) :
std::string(node_->name) + "_" + socket_out_->name);
}
return res;
}

View File

@ -13,12 +13,12 @@
namespace blender::nodes::materialx {
class NodeParser {
public:
MaterialX::GraphElement *graph;
const Depsgraph *depsgraph;
const Material *material;
const bNode *node;
const bNodeSocket *socket_out;
protected:
MaterialX::GraphElement *graph_;
const Depsgraph *depsgraph_;
const Material *material_;
const bNode *node_;
const bNodeSocket *socket_out_;
public:
NodeParser(MaterialX::GraphElement *graph,

View File

@ -21,7 +21,7 @@ NodeItem OutputMaterialNodeParser::compute()
NodeItem OutputMaterialNodeParser::compute(const std::string &socket_name)
{
NodeItem surface = empty();
if (node) {
if (node_) {
surface = get_input_link(socket_name);
}
else {
@ -37,15 +37,15 @@ NodeItem OutputMaterialNodeParser::compute(const std::string &socket_name)
NodeItem OutputMaterialNodeParser::compute_default()
{
NodeItem surface = create_node("standard_surface", "surfaceshader");
surface.set_input("base_color", value(MaterialX::Color3(material->r, material->g, material->b)));
surface.set_input("diffuse_roughness", value(material->roughness));
if (material->metallic > 0.0f) {
surface.set_input("metalness", value(material->metallic));
surface.set_input("base_color", value(MaterialX::Color3(material_->r, material_->g, material_->b)));
surface.set_input("diffuse_roughness", value(material_->roughness));
if (material_->metallic > 0.0f) {
surface.set_input("metalness", value(material_->metallic));
}
if (material->spec) {
surface.set_input("specular", value(material->spec));
surface.set_input("specular_color", value(material->spec));
surface.set_input("specular_roughness", value(material->roughness));
if (material_->spec) {
surface.set_input("specular", value(material_->spec));
surface.set_input("specular_color", value(material_->spec));
surface.set_input("specular_roughness", value(material_->roughness));
}
NodeItem res = create_node("surfacematerial", "material");

View File

@ -12,10 +12,10 @@ namespace blender::nodes::materialx {
NodeItem TexEnvironmentNodeParser::compute()
{
Image *image = (Image *)node->id;
NodeTexEnvironment *tex = static_cast<NodeTexEnvironment *>(node->storage);
Scene *scene = DEG_get_input_scene(depsgraph);
Main *bmain = DEG_get_bmain(depsgraph);
Image *image = (Image *)node_->id;
NodeTexEnvironment *tex = static_cast<NodeTexEnvironment *>(node_->storage);
Scene *scene = DEG_get_input_scene(depsgraph_);
Main *bmain = DEG_get_bmain(depsgraph_);
std::string image_path;
/* TODO: What if Blender built without Hydra? Also io::hydra::cache_or_get_image_file contains
* pretty general code, so could be moved from bf_usd project. */

View File

@ -12,10 +12,10 @@ namespace blender::nodes::materialx {
NodeItem TexImageNodeParser::compute()
{
Image *image = (Image *)node->id;
NodeTexImage *tex = static_cast<NodeTexImage *>(node->storage);
Scene *scene = DEG_get_input_scene(depsgraph);
Main *bmain = DEG_get_bmain(depsgraph);
Image *image = (Image *)node_->id;
NodeTexImage *tex = static_cast<NodeTexImage *>(node_->storage);
Scene *scene = DEG_get_input_scene(depsgraph_);
Main *bmain = DEG_get_bmain(depsgraph_);
std::string image_path;
/* TODO: What if Blender built without Hydra? Also io::hydra::cache_or_get_image_file contains
* pretty general code, so could be moved from bf_usd project. */