Maya: Direct Connection Vertex Color to Vertex Position

Hi,

I’m trying to take a poly model, and duplicate it.

I then want to offset the duped model’s vertices along their normals by some offset value.

Right now I’m storing the original meshes’ vertex world positions xyz to the rgb values of a vertex color map on the dupe. I’m also painting a second rgb vertex color map on the duped object for offset values (0=leave it be, 1=move it the max).

Everything should be live connections for the next part so it updates in real time.

I could keep this approach if theres a way for me to direct connect the vertex’s color to its world position. I’d also need to be able to move the vertex along its normal tho and honestly i can’t remember the vector math needed to do that. I can obviously get the unit vector of the normal but I’m not sure what to do from there? Do I multiply the unit vector’s components each by the magnitude and then do a cross product or do i add them… that seems odd?

I can make all this happen right now as a scripted process that executes and updates the values, but i want it to be live and i can’t figure out a way to connect the vertex color map values to the vertex positions. I was originally doing it with cmds (polyColorPerVertex() and moveVertexAlongDirection()) but its very slow processing out the values per vertex on even medium meshes, so i switched it over to openmaya and it sped up like crazy but that still doesnt address how to direct connect them.

Any help would be greatly appreciated!

The way with the least amount of hassle is to just use the Texture deformer with “direction” set to “Normal”. Set the texture to all white, and then you can just paint the textureDeformer-weights. Then just play around with the sliders to get what you want.

At work, we just wrote a quick c++ deformer. And this is the perfect first c++ deformer to write because it’s so simple. All the data you need is available through convenience functions right on the MItGeometry object that gets passed to MPxDeformerNode::deform.

2 Likes

funny a texture deformer is actually a way i could approach it. i’ll test it out and see the performance.

I could go the route of writing a deformer. maybe i’ll poke at that.

I’m definitely still curious if theres any native direct way to do it too though.

Thanks for the ideas!

I’m gonna go out on a limb and say there probably isn’t a direct way to do it… at least without writing a new node or two… or 20. And, to be fair, that could be an interesting paradigm, but I don’t think it would work well with Maya’s choice of node interaction, but I’d LOVE to be proven wrong.

Now I’m just speculating: To do it at the node level, I think you’d have to start writing low-level operators (+ - / * ^ . x etc) that work with maya’s array typed plugs (maya’s existing arithmetic nodes are terrible). Then you’d have to write nodes that separate out that data in a way you could access it via plugs. Then there’s the per-node choice of an array of single plugs vs. a single plug that holds an entire array that starts adding complication … And I don’t know that this would be at all efficient when all is said and done.

You can already easily do this kind of stuff in bifrost though… but I’m not sure I’d actually recommend that yet unless it was just a one-off.

1 Like

Yea it’s definitely interesting because at first it seemed like it should be an easy thing to achieve to me. But the available plugs dont seem to provide an easy path to it.

I guess i could essentially house the math all stuffed in a new node that takes a random array size and processes it all out. i do think itd be slower in general, but i’m not sure how much of a hit.

good point on bifrost. i wouldn’t mind doing it in the bifrost graph and you’re right it is kind of built for this kind of thing, hadnt really considered it. curious your hesitancy on doing it by the bifrost graph?

thanks for the thoughts!

I’m worried that if this was a deformer used in a rig multiple times in an animator’s file, then the extra overhead to use bifrost for such a simple thing would outweigh most gains.

But if you’re running some automated process where you don’t really care about interaction speed, and you just need that flexibility, then do what you gotta do.

1 Like

I ended up writing a plugin in python openmaya.
its pretty speedy.
It generates the connections almost instantly and runs very smooth in scene too even with smooth skins and blend shapes.
Was a good exercise in plugin creation. Haven’t really done much with plugins before.

1 Like