PDA

View Full Version : How to add a vector attribute to a node?


robitabu
11-08-2011, 09:24 AM
Is it only possible with addAttr by adding a new array of vectors (and not simply a vector data type attribute)? Am I missing something?

Robert Bateman
11-08-2011, 10:49 AM
Yes. MFnNumericAttribute::setArray(true / false);

In all other regards, the process for creating a single vector, or a an array of vectors, is identical.

NaughtyNathan
11-08-2011, 04:42 PM
I'm guessing Roberto is talking about simple MEL as he mentions addAttr. There is no "vector" type attribute in the same way that there is a vector variable type. If you want to add an attribute that looks and works like a 3 component vector you need to add a float3 or double3:
addAttr -ln "myVectorAttr" -at "float3" pCube1;
addAttr -ln "myVectorAttrX" -at "float" -parent "myVectorAttr" -dv 0.0 pCube1;
addAttr -ln "myVectorAttrY" -at "float" -parent "myVectorAttr" -dv 1.0 pCube1;
addAttr -ln "myVectorAttrZ" -at "float" -parent "myVectorAttr" -dv 0.0 pCube1;
vector $V = `getAttr pCube1.myVectorAttr`;

I assume this is what you're after...?
:nathaN

robitabu
11-08-2011, 06:30 PM
I'm guessing Roberto is talking about simple MEL as he mentions addAttr. There is no "vector" type attribute in the same way that there is a vector variable type. If you want to add an attribute that looks and works like a 3 component vector you need to add a float3 or double3:

addAttr -ln "myVectorAttr" -at "float3" pCube1;
addAttr -ln "myVectorAttrX" -at "float" -parent "myVectorAttr" -dv 0.0 pCube1;
addAttr -ln "myVectorAttrY" -at "float" -parent "myVectorAttr" -dv 1.0 pCube1;
addAttr -ln "myVectorAttrZ" -at "float" -parent "myVectorAttr" -dv 0.0 pCube1;
vector $V = `getAttr pCube1.myVectorAttr`;

I assume this is what you're after...?
:nathaN

That's more likely it :-)

I was playing with Maya a bit in the meanwhile and looked how its UI interface does that (Attribute Editor -> Attributes -> Add Attributes ...), quite the same as you suggest.

This is what Maya is doing:

addAttr -ln "newVector" -at double3 |pCube1;
addAttr -ln "newVectorX" -at double -p newVector |pCube1;
addAttr -ln "newVectorY" -at double -p newVector |pCube1;
addAttr -ln "newVectorZ" -at double -p newVector |pCube1;
setAttr -type double3 |pCube1.newVector 0 0 0;


Anyway, I was initially referring to Maya's Reference addAttr page, that clearly mentions a "-dt vectorArray" option. This is totally different stuff.

I only wonder how the double3/float3 difference may concern me ...

NaughtyNathan
11-08-2011, 07:46 PM
I wouldn't worry about the difference. double is just a higher precision float, and considering we're talking about MEL scripting here, where low level memory concerns are almost entirely irrelevant, I can't see any reason to use floats over doubles... The only reason I used them in my example was because "float" is a more familiar variable type to most people whereas "double" just draws blank stares from the majority of "normal" users.

:nathaN

robitabu
11-08-2011, 07:56 PM
I wouldn't worry about the difference.
...
The only reason I used them in my example was because "float" is a more familiar variable type to most people whereas "double" just draws blank stares from the majority of "normal" users.


And it would be more consistent too, since the idea is to use that attribute for storing a vector variable which, by definition, is a triple of floats.

Anyway, thx Nathan, you're always spot on :-)

CGTalk Moderation
11-08-2011, 07:56 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.