forked from blender/blender
matx-code-improvements #8
@ -10,7 +10,7 @@ namespace blender::nodes::materialx {
|
|||||||
NodeItem MathNodeParser::compute()
|
NodeItem MathNodeParser::compute()
|
||||||
{
|
{
|
||||||
/* TODO: finish some math operations */
|
/* TODO: finish some math operations */
|
||||||
auto op = node->custom1;
|
auto op = node_->custom1;
|
||||||
NodeItem res = empty();
|
NodeItem res = empty();
|
||||||
|
|
||||||
/* Single operand operations */
|
/* 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) {
|
if (clamp_output && res) {
|
||||||
res = res.clamp();
|
res = res.clamp();
|
||||||
}
|
}
|
||||||
|
@ -14,50 +14,50 @@ NodeParser::NodeParser(MaterialX::GraphElement *graph,
|
|||||||
const Material *material,
|
const Material *material,
|
||||||
const bNode *node,
|
const bNode *node,
|
||||||
const bNodeSocket *socket_out)
|
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 NodeParser::create_node(const std::string &mx_category, const std::string &mx_type)
|
||||||
{
|
{
|
||||||
NodeItem res = empty();
|
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;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeItem NodeParser::get_input_default(const std::string &name)
|
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)
|
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)
|
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)
|
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)
|
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)
|
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
|
NodeItem NodeParser::empty() const
|
||||||
{
|
{
|
||||||
return NodeItem(graph);
|
return NodeItem(graph_);
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeItem NodeParser::get_input_default(const bNodeSocket &socket)
|
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 */
|
/* Computing from_node with required NodeParser object */
|
||||||
#define CASE_NODE_TYPE(type, T) \
|
#define CASE_NODE_TYPE(type, T) \
|
||||||
case type: \
|
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;
|
break;
|
||||||
|
|
||||||
switch (from_node->typeinfo->type) {
|
switch (from_node->typeinfo->type) {
|
||||||
@ -143,12 +143,12 @@ NodeItem NodeParser::get_input_value(const bNodeSocket &socket)
|
|||||||
|
|
||||||
NodeItem NodeParser::compute_full()
|
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();
|
NodeItem res = compute();
|
||||||
if (res.node) {
|
if (res.node) {
|
||||||
res.set_name(node->output_sockets().size() == 1 ?
|
res.set_name(node_->output_sockets().size() == 1 ?
|
||||||
std::string(node->name) :
|
std::string(node_->name) :
|
||||||
std::string(node->name) + "_" + socket_out->name);
|
std::string(node_->name) + "_" + socket_out_->name);
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
@ -13,12 +13,12 @@
|
|||||||
namespace blender::nodes::materialx {
|
namespace blender::nodes::materialx {
|
||||||
|
|
||||||
class NodeParser {
|
class NodeParser {
|
||||||
public:
|
protected:
|
||||||
MaterialX::GraphElement *graph;
|
MaterialX::GraphElement *graph_;
|
||||||
const Depsgraph *depsgraph;
|
const Depsgraph *depsgraph_;
|
||||||
const Material *material;
|
const Material *material_;
|
||||||
const bNode *node;
|
const bNode *node_;
|
||||||
const bNodeSocket *socket_out;
|
const bNodeSocket *socket_out_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
NodeParser(MaterialX::GraphElement *graph,
|
NodeParser(MaterialX::GraphElement *graph,
|
||||||
|
@ -21,7 +21,7 @@ NodeItem OutputMaterialNodeParser::compute()
|
|||||||
NodeItem OutputMaterialNodeParser::compute(const std::string &socket_name)
|
NodeItem OutputMaterialNodeParser::compute(const std::string &socket_name)
|
||||||
{
|
{
|
||||||
NodeItem surface = empty();
|
NodeItem surface = empty();
|
||||||
if (node) {
|
if (node_) {
|
||||||
surface = get_input_link(socket_name);
|
surface = get_input_link(socket_name);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -37,15 +37,15 @@ NodeItem OutputMaterialNodeParser::compute(const std::string &socket_name)
|
|||||||
NodeItem OutputMaterialNodeParser::compute_default()
|
NodeItem OutputMaterialNodeParser::compute_default()
|
||||||
{
|
{
|
||||||
NodeItem surface = create_node("standard_surface", "surfaceshader");
|
NodeItem surface = create_node("standard_surface", "surfaceshader");
|
||||||
surface.set_input("base_color", value(MaterialX::Color3(material->r, material->g, material->b)));
|
surface.set_input("base_color", value(MaterialX::Color3(material_->r, material_->g, material_->b)));
|
||||||
surface.set_input("diffuse_roughness", value(material->roughness));
|
surface.set_input("diffuse_roughness", value(material_->roughness));
|
||||||
if (material->metallic > 0.0f) {
|
if (material_->metallic > 0.0f) {
|
||||||
surface.set_input("metalness", value(material->metallic));
|
surface.set_input("metalness", value(material_->metallic));
|
||||||
}
|
}
|
||||||
if (material->spec) {
|
if (material_->spec) {
|
||||||
surface.set_input("specular", value(material->spec));
|
surface.set_input("specular", value(material_->spec));
|
||||||
surface.set_input("specular_color", value(material->spec));
|
surface.set_input("specular_color", value(material_->spec));
|
||||||
surface.set_input("specular_roughness", value(material->roughness));
|
surface.set_input("specular_roughness", value(material_->roughness));
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeItem res = create_node("surfacematerial", "material");
|
NodeItem res = create_node("surfacematerial", "material");
|
||||||
|
@ -12,10 +12,10 @@ namespace blender::nodes::materialx {
|
|||||||
|
|
||||||
NodeItem TexEnvironmentNodeParser::compute()
|
NodeItem TexEnvironmentNodeParser::compute()
|
||||||
{
|
{
|
||||||
Image *image = (Image *)node->id;
|
Image *image = (Image *)node_->id;
|
||||||
NodeTexEnvironment *tex = static_cast<NodeTexEnvironment *>(node->storage);
|
NodeTexEnvironment *tex = static_cast<NodeTexEnvironment *>(node_->storage);
|
||||||
Scene *scene = DEG_get_input_scene(depsgraph);
|
Scene *scene = DEG_get_input_scene(depsgraph_);
|
||||||
Main *bmain = DEG_get_bmain(depsgraph);
|
Main *bmain = DEG_get_bmain(depsgraph_);
|
||||||
std::string image_path;
|
std::string image_path;
|
||||||
/* TODO: What if Blender built without Hydra? Also io::hydra::cache_or_get_image_file contains
|
/* 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. */
|
* pretty general code, so could be moved from bf_usd project. */
|
||||||
|
@ -12,10 +12,10 @@ namespace blender::nodes::materialx {
|
|||||||
|
|
||||||
NodeItem TexImageNodeParser::compute()
|
NodeItem TexImageNodeParser::compute()
|
||||||
{
|
{
|
||||||
Image *image = (Image *)node->id;
|
Image *image = (Image *)node_->id;
|
||||||
NodeTexImage *tex = static_cast<NodeTexImage *>(node->storage);
|
NodeTexImage *tex = static_cast<NodeTexImage *>(node_->storage);
|
||||||
Scene *scene = DEG_get_input_scene(depsgraph);
|
Scene *scene = DEG_get_input_scene(depsgraph_);
|
||||||
Main *bmain = DEG_get_bmain(depsgraph);
|
Main *bmain = DEG_get_bmain(depsgraph_);
|
||||||
std::string image_path;
|
std::string image_path;
|
||||||
/* TODO: What if Blender built without Hydra? Also io::hydra::cache_or_get_image_file contains
|
/* 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. */
|
* pretty general code, so could be moved from bf_usd project. */
|
||||||
|
Loading…
Reference in New Issue
Block a user