forked from blender/blender
Implement type conversion for NodeItem #9
@ -238,15 +238,20 @@ NodeItem NodeItem::exp() const
|
|||||||
|
|
||||||
NodeItem NodeItem::convert(Type to_type) const
|
NodeItem NodeItem::convert(Type to_type) const
|
||||||
{
|
{
|
||||||
Type t = type();
|
Type tp = type();
|
||||||
BogdanNagirniak marked this conversation as resolved
Outdated
|
|||||||
if (t == to_type) {
|
if (tp == to_type) {
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
if (!is_arithmetic(t) || !is_arithmetic(to_type)) {
|
if (!is_arithmetic(tp) || !is_arithmetic(to_type)) {
|
||||||
return empty();
|
return empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (t) {
|
if (to_type == Type::Float) {
|
||||||
|
/* TODO: Convert to float, <extract> should be used */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Converting types which requires > 1 iteration */
|
||||||
|
switch (tp) {
|
||||||
case Type::Vector2:
|
case Type::Vector2:
|
||||||
switch (to_type) {
|
switch (to_type) {
|
||||||
case Type::Vector4:
|
case Type::Vector4:
|
||||||
@ -301,9 +306,10 @@ NodeItem NodeItem::convert(Type to_type) const
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Converting 1 iteration types */
|
||||||
NodeItem res = empty();
|
NodeItem res = empty();
|
||||||
if (value) {
|
if (value) {
|
||||||
switch (t) {
|
switch (tp) {
|
||||||
case Type::Float: {
|
case Type::Float: {
|
||||||
float v = value->asA<float>();
|
float v = value->asA<float>();
|
||||||
switch (to_type) {
|
switch (to_type) {
|
||||||
@ -492,9 +498,9 @@ void NodeItem::set_input(const std::string &name,
|
|||||||
const std::string &output_name)
|
const std::string &output_name)
|
||||||
{
|
{
|
||||||
if (item.value) {
|
if (item.value) {
|
||||||
Type t = item.type();
|
Type tp = item.type();
|
||||||
std::string mx_type = type(t);
|
std::string mx_type = type(tp);
|
||||||
switch (t) {
|
switch (tp) {
|
||||||
case Type::String:
|
case Type::String:
|
||||||
set_input(name, item.value->asA<std::string>(), mx_type);
|
set_input(name, item.value->asA<std::string>(), mx_type);
|
||||||
break;
|
break;
|
||||||
@ -634,13 +640,13 @@ bool NodeItem::is_arithmetic() const
|
|||||||
NodeItem NodeItem::arithmetic(const std::string &category, std::function<float(float)> func) const
|
NodeItem NodeItem::arithmetic(const std::string &category, std::function<float(float)> func) const
|
||||||
{
|
{
|
||||||
NodeItem res = empty();
|
NodeItem res = empty();
|
||||||
Type t = type();
|
Type tp = type();
|
||||||
if (!is_arithmetic(t)) {
|
if (!is_arithmetic(tp)) {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (value) {
|
if (value) {
|
||||||
switch (t) {
|
switch (tp) {
|
||||||
case Type::Float: {
|
case Type::Float: {
|
||||||
float v = value->asA<float>();
|
float v = value->asA<float>();
|
||||||
res.value = MaterialX::Value::createValue<float>(func(v));
|
res.value = MaterialX::Value::createValue<float>(func(v));
|
||||||
@ -679,7 +685,7 @@ NodeItem NodeItem::arithmetic(const std::string &category, std::function<float(f
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
res.node = graph_->addNode(category, MaterialX::EMPTY_STRING, type(t));
|
res.node = graph_->addNode(category, MaterialX::EMPTY_STRING, type(tp));
|
||||||
res.set_input("in", *this);
|
res.set_input("in", *this);
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
|
@ -19,7 +19,7 @@ NodeItem TexCheckerNodeParser::compute()
|
|||||||
vector = vector * scale;
|
vector = vector * scale;
|
||||||
|
|
||||||
NodeItem separate = create_node("separate2", "multioutput");
|
NodeItem separate = create_node("separate2", "multioutput");
|
||||||
separate.set_input("in", vector);
|
separate.set_input("in", vector, NodeItem::Type::Vector2);
|
||||||
separate.add_output("outx", NodeItem::Type::Float);
|
separate.add_output("outx", NodeItem::Type::Float);
|
||||||
separate.add_output("outy", NodeItem::Type::Float);
|
separate.add_output("outy", NodeItem::Type::Float);
|
||||||
|
|
||||||
|
@ -16,10 +16,11 @@ NodeItem TexNoiseNodeParser::compute()
|
|||||||
detail = value(int(detail.value->asA<float>()));
|
detail = value(int(detail.value->asA<float>()));
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeItem texcoord = create_node("position", "vector3");
|
NodeItem position = create_node("position", "vector3");
|
||||||
|
position = position * scale;
|
||||||
|
|
||||||
NodeItem res = create_node("fractal3d", "color3");
|
NodeItem res = create_node("fractal3d", "color3");
|
||||||
res.set_input("position", texcoord * scale);
|
res.set_input("position", position, NodeItem::Type::Vector3);
|
||||||
res.set_input("octaves", detail);
|
res.set_input("octaves", detail);
|
||||||
res.set_input("lacunarity", lacunarity);
|
res.set_input("lacunarity", lacunarity);
|
||||||
return res;
|
return res;
|
||||||
|
Loading…
Reference in New Issue
Block a user
tp -> from_type