Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

Does a Math Round or Floor node exist in Maya?

Does a Math Round or Floor node exist in Maya?

dkrelina
Advocate Advocate
7,512 Views
17 Replies
Message 1 of 18

Does a Math Round or Floor node exist in Maya?

dkrelina
Advocate
Advocate

Hi,

 

I would like to take the float output of one node and have it connect to another node in "stepping" integer values. Ideally using a node rather than with an expressions.

 

I'm looking for a Floor or Round node, or a node that will convert a float to an int.

 

Thank you!

0 Likes
Accepted solutions (1)
7,513 Views
17 Replies
Replies (17)
Message 2 of 18

mspeer
Consultant
Consultant

Hi!

There should be multiple options, from simple "Ramp" node up to "aiFloatToInt".

0 Likes
Message 3 of 18

dkrelina
Advocate
Advocate

@mspeer how would a ramp work?

 

Say I have a floatConstant with a value 2.7 and I wanted it to round to 3.

 

How would I use the ramp? Like this?

 

floatConstant.outFloat > ramp.vCoord

and then use ramp.outColorR as my out value? This gives repeating values that cycle between 0 and 1.

0 Likes
Message 4 of 18

zewt
Collaborator
Collaborator
Accepted solution

If you connect a float attribute to an integer attribute it'll round automatically.  If you need to round a float to a float, you can put an integer attribute on any node and connect through it.  The input will round, and the output will be the rounded value.

 

0 Likes
Message 5 of 18

mspeer
Consultant
Consultant

Hi!

 

"...This gives repeating values that cycle between 0 and 1".

You can create any output you want, but the input range is limited from 0 to 1.

There are plenty of nodes available to modify a used range to overcome this limitation (Remap, Set Range,...).

0 Likes
Message 6 of 18

dkrelina
Advocate
Advocate

@zewt thank you. Using the approach you suggest, do I need to create an empty transform (an empty group), add a new integer attribute to it, then connect the float to it as an input? I tried this and it seems to work. But do I always need to create a new empty group an add a new attribute, or is there a simpler way? Or a standalone node to achieve the same?

0 Likes
Message 7 of 18

dkrelina
Advocate
Advocate

@mspeer I'm trying to convert a float to an int. I still don't see how a remap or set range would let me achieve this. The range is not an issue. It's rather the "stepping values" effect that I'm looking for... imagine a range of 0 to positive infinity as integers, where for example, input is 2.321, 3.641, 17.206 and output is 2, 4, 17.

0 Likes
Message 8 of 18

mspeer
Consultant
Consultant

Hi!

 

 

ramp_int.gif

 

The maximum different numbers is limited by the amount of color positions you add.

0 Likes
Message 9 of 18

alexkzy
Contributor
Contributor

This could help you:

https://apps.autodesk.com/MAYA/en/Detail/Index?id=212304226072872821&appLang=en&os=Win64

 

You could code it yourself as well so that you can stay with vanilla maya.

0 Likes
Message 10 of 18

zewt
Collaborator
Collaborator

You can use an arbitrary DG node, like a multiplyDivide node.  Just ignore the node's attributes and add your own.  I do wish there was a builtin "do nothing" DG node to put things like this on.  (I've created my own for exactly this: https://zewt.github.io/zMayaTools/zNode.html  You probably don't want to use a plugin just for that, though.)  You can also just put an attribute on the same node as the one you're converting.

 

(I'd avoid ramp for this.  You need a lot of entries if your attribute has a wide range, and it would take extra work to handle negative numbers since ramp positions can't be negative.  If you're using Arnold, also note that it only supports up to 16 ramp entries.)

 

0 Likes
Message 11 of 18

dkrelina
Advocate
Advocate

@mspeer ahh, I see. This approach would work well when working with a limited range or for non-linear remapping.

0 Likes
Message 12 of 18

dkrelina
Advocate
Advocate

@zewt thanks for the tips! I will definitely have to look into your zMayaTools as they look quite useful. I'm pleasantly surprised to see that you have a Copy Deformer Weights tool. It's always been shocking to me that this is not included in out of the box Maya!

0 Likes
Message 13 of 18

dkrelina
Advocate
Advocate

@alexkzy how would I go about coding it myself? Are you talking about using an expression like this?

 

 

node2.myInt = floor(node1.myFloat);

 

Capture.PNG

 

I have a few questions about using this approach:

  1. I worked with a rigger a while ago who recommended I stay away from expressions as much as possible and that doing things through nodes was more efficient. Is this true? What is the most efficient way to code my own functionality?
  2. I find expressions in Maya to be hard to read. Is there a way to name the inputs on the expression node? (thus making it easier to link up connections in the node editor) I've become accustomed to working with Unreal's custom code node, which lets you define and name inputs. Does something like this exist in Maya?

T_Custom_Node.png

 

0 Likes
Message 14 of 18

zewt
Collaborator
Collaborator

Limited expression use can be better than using a big, complicated node network for things that aren't easy to represent with existing nodes.  They can be a pain to edit, since the expression editor UI is an antique (it would be so much nicer if you could just select an expression node and edit the expression in the AE).  They're not that slow, but I think they'll only evaluate in the main thread, so they won't parallelize with the rest of the rig. You'll want to check their impact on performance with the profiler, but you need to do that for anything.

 

The biggest limitation of expressions is that they don't work with shading networks, like mspeer's banded texture example above.

 

FYI, I threw this in the ideas forum, for a place to put things like a rounding integer attribute: https://forums.autodesk.com/t5/maya-ideas/add-a-simple-empty-dg-node-type-for-storing-data/idi-p/892... I've wanted something like that several times too.  zMayaTools has zNode, but even I don't really use it, since I don't want to make things depend on external nodes (even my own) unnecessarily...

 

Message 15 of 18

alexkzy
Contributor
Contributor

Yes, this is one way that I was talking about.

If you want to change the expression afterwards, just use the script editor and change it. The expression is a string attribute of the expression node. Same for input/output except those are float arrays.

 

https://download.autodesk.com/us/maya/2008help/Nodes/expression.html

 

Nodes are visuall representation of code so there is not difference performance-wise in general. But I guess this question highly depends on what you are doing and how you want to achieve it. I think it's all about usability and how efficient you can get things done.

 

If you put time into coding, you will get better at reading the expressions. Sadly (in my opinion) MEL is a very unreadable language overall but don't be afraid, it's all about practice.

 

https://courses.cs.washington.edu/courses/cse459/06wi/help/mayaguide/Complete/MEL_Expressions.pdf

Message 16 of 18

zewt
Collaborator
Collaborator

There's definitely a difference in performance between expressions in MEL and computes done with native nodes.  (Nodes aren't a visual representation of MEL.)  For small expressions it usually won't matter, but always use the profiler to check.

 

Message 17 of 18

BurkhardRammner
Collaborator
Collaborator

why did nobody mention 'cgdna'?

https://forums.autodesk.com/t5/maya-ideas/add-more-math-trig-nodes/idi-p/7963332

(looks like the source code is no longer on the net??? -> I have it if you want it)

 

or 'maya-math-nodes'?

https://github.com/serguei-k/maya-math-nodes

 

0 Likes
Message 18 of 18

hoathinhvietnam2016
Observer
Observer

for  flooring  values in Maya using nodes:

I did like this float value subtract 0.49999 then connect to an integer attribute 

 

for  ceiling values in Maya using nodes:

float value plus 0.49999 then connect to an integer attribute 

0 Likes