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
|
||||
{
|
||||
Type t = type();
|
||||
if (t == to_type) {
|
||||
Type tp = type();
|
||||
if (tp == to_type) {
|
||||
return *this;
|
||||
}
|
||||
if (!is_arithmetic(t) || !is_arithmetic(to_type)) {
|
||||
if (!is_arithmetic(tp) || !is_arithmetic(to_type)) {
|
||||
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:
|
||||
switch (to_type) {
|
||||
case Type::Vector4:
|
||||
@ -301,9 +306,10 @@ NodeItem NodeItem::convert(Type to_type) const
|
||||
break;
|
||||
}
|
||||
|
||||
/* Converting 1 iteration types */
|
||||
NodeItem res = empty();
|
||||
if (value) {
|
||||
switch (t) {
|
||||
switch (tp) {
|
||||
case Type::Float: {
|
||||
float v = value->asA<float>();
|
||||
switch (to_type) {
|
||||
@ -492,9 +498,9 @@ void NodeItem::set_input(const std::string &name,
|
||||
const std::string &output_name)
|
||||
{
|
||||
if (item.value) {
|
||||
Type t = item.type();
|
||||
std::string mx_type = type(t);
|
||||
switch (t) {
|
||||
Type tp = item.type();
|
||||
std::string mx_type = type(tp);
|
||||
switch (tp) {
|
||||
case Type::String:
|
||||
set_input(name, item.value->asA<std::string>(), mx_type);
|
||||
break;
|
||||
@ -634,13 +640,13 @@ bool NodeItem::is_arithmetic() const
|
||||
NodeItem NodeItem::arithmetic(const std::string &category, std::function<float(float)> func) const
|
||||
{
|
||||
NodeItem res = empty();
|
||||
Type t = type();
|
||||
if (!is_arithmetic(t)) {
|
||||
Type tp = type();
|
||||
if (!is_arithmetic(tp)) {
|
||||
return res;
|
||||
}
|
||||
|
||||
if (value) {
|
||||
switch (t) {
|
||||
switch (tp) {
|
||||
case Type::Float: {
|
||||
float v = value->asA<float>();
|
||||
res.value = MaterialX::Value::createValue<float>(func(v));
|
||||
@ -679,7 +685,7 @@ NodeItem NodeItem::arithmetic(const std::string &category, std::function<float(f
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
return res;
|
||||
|
@ -19,7 +19,7 @@ NodeItem TexCheckerNodeParser::compute()
|
||||
vector = vector * scale;
|
||||
|
||||
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("outy", NodeItem::Type::Float);
|
||||
|
||||
|
@ -16,10 +16,11 @@ NodeItem TexNoiseNodeParser::compute()
|
||||
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");
|
||||
res.set_input("position", texcoord * scale);
|
||||
res.set_input("position", position, NodeItem::Type::Vector3);
|
||||
res.set_input("octaves", detail);
|
||||
res.set_input("lacunarity", lacunarity);
|
||||
return res;
|
||||
|
Loading…
Reference in New Issue
Block a user