rewrite maya follicle node

436 views
Skip to first unread message

Zhen Huang

unread,
Nov 19, 2018, 3:57:49 AM11/19/18
to Python Programming for Autodesk Maya
Hi , 

I want to rewrite maya follicle node , the idea for this is because :
----1 , polygon basic follicle is much faster than classic rivet , even matrix basic rivet , I think it's because the extra calculation on 'curveFromEdge' and 'loft' 
----2 , maya default follicle can't change axis of orientation 
And I'd like to remove the rest of dynamic parameters and functions.

From the rough view , seems the follicle node read the position and tangent from polygoon directly , and after researching the MFnMesh class , I don't get any function like getPositionAtUV or getNormalAtUV , getTangentAtUV .

Will be a great appreciation if you can figure out the key of this custom follicle node .


Big Thanks and best ,
John HZ 

Angelo Sta. Catalina

unread,
Nov 19, 2018, 9:30:17 AM11/19/18
to python_in...@googlegroups.com
Why not just use MFnMesh.getPoint? Build an orthonormal coordinate using connected points.

Zhen Huang

unread,
Nov 20, 2018, 3:07:34 AM11/20/18
to Python Programming for Autodesk Maya
Seems a good idea , are you mind introduce more please . Thanks .

I found the MFnMesh updated a lot , there is a getPointAtUV method . Position solved .

How about rotation , any idea ?

Normal can get from interpolation of 3 points normal . 
Tangent should base on UV , have no idea yet . 

在 2018年11月19日星期一 UTC+8下午10:30:17,Angelo写道:

Angelo Sta. Catalina

unread,
Nov 20, 2018, 8:54:52 AM11/20/18
to python_in...@googlegroups.com
I recommend you get Chad Vernon's "Applied 3d Math" video tutorial found here.

It goes over how to construct rotation from 3 points (basically a rivet). 

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/fd0ea781-6f68-4574-a9cb-ca7fb32bbbc2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Michael Boon

unread,
Nov 20, 2018, 10:54:23 PM11/20/18
to Python Programming for Autodesk Maya
You can get the tangent and binormal at each corner of a face of a MFnMesh. Those are based on the UV directions. You would have to choose one, or interpolate for a position in the middle of a face.


On Wednesday, 21 November 2018 00:54:52 UTC+11, Angelo wrote:
I recommend you get Chad Vernon's "Applied 3d Math" video tutorial found here.

It goes over how to construct rotation from 3 points (basically a rivet). 

On Tue, Nov 20, 2018 at 2:07 AM Zhen Huang <qeej...@gmail.com> wrote:
Seems a good idea , are you mind introduce more please . Thanks .

I found the MFnMesh updated a lot , there is a getPointAtUV method . Position solved .

How about rotation , any idea ?

Normal can get from interpolation of 3 points normal . 
Tangent should base on UV , have no idea yet . 

在 2018年11月19日星期一 UTC+8下午10:30:17,Angelo写道:
Why not just use MFnMesh.getPoint? Build an orthonormal coordinate using connected points.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.

Zhen Huang

unread,
Nov 21, 2018, 1:14:36 AM11/21/18
to Python Programming for Autodesk Maya
Hi Angelo , 

Thanks ! Awesome turorial , I'm going to use this solution after follicle style method , seems ti's a pure math method base on triangle shape , should be a faster solution . 

在 2018年11月20日星期二 UTC+8下午9:54:52,Angelo写道:
I recommend you get Chad Vernon's "Applied 3d Math" video tutorial found here.

It goes over how to construct rotation from 3 points (basically a rivet). 

On Tue, Nov 20, 2018 at 2:07 AM Zhen Huang <qeej...@gmail.com> wrote:
Seems a good idea , are you mind introduce more please . Thanks .

I found the MFnMesh updated a lot , there is a getPointAtUV method . Position solved .

How about rotation , any idea ?

Normal can get from interpolation of 3 points normal . 
Tangent should base on UV , have no idea yet . 

在 2018年11月19日星期一 UTC+8下午10:30:17,Angelo写道:
Why not just use MFnMesh.getPoint? Build an orthonormal coordinate using connected points.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.

Zhen Huang

unread,
Nov 21, 2018, 1:19:04 AM11/21/18
to Python Programming for Autodesk Maya
Thanks Michael , I found a api function to have the correctly normal and tangents depends on UV directions which called MItMeshPolygon.getAxisAtUV , perfectly matched follicle's behavior , will post out soon . 

在 2018年11月21日星期三 UTC+8上午11:54:23,Michael Boon写道:

zhen huang

unread,
Nov 21, 2018, 10:52:04 AM11/21/18
to Python Programming for Autodesk Maya
Hey , before going to C++ I wrote a python script to verify , it works great , the behavior totally same as maya default follicle .

02.png03.png01.png


As you can see , I test with 2 poly cubes with same manually tweaked UV , the method works both hard edge and soft edge . Post the script below just a feedback of this subject.


Currently not sure the speed yet , cos it hasn't been converted to C++ . Will have a final feedback about this method .  Thanks !




import maya.OpenMaya as om 

import pymel.core as pm 


def getDagPath(node):

selectionList = om.MSelectionList()

selectionList.add(node)

pathNode = om.MDagPath()

selectionList.getDagPath(0, pathNode)

return pathNode



###### inputs 

meshShape = 'pCubeShape1'

#uv = [0.415 , 0.495]

uvs = [(0.415,0.495) , (0.339 , 0.535)]


### use pymel to get api function and dag path  

#pmm = pm.PyNode('pCubeShape1')

#dag = pmm.__apimdagpath__()

#fm = pmm.__apimfn__()


### use api to get function and dag path

dag = getDagPath(meshShape)

fm = om.MFnMesh(dag)



###### compute start 

### 

util2 = om.MScriptUtil()

### define normal tangents 

normal = om.MVector()

uTangent = om.MVector()

vTangent = om.MVector()

### define pos MPoint

pos = om.MPoint(0.0,0.0,0.0)

### walk through meshPolygon , try to just walk through just one time for multiply inputs to save calculation time 

faceIndex = -1

mit = om.MItMeshPolygon(dag)

outMatrixes = om.MMatrixArray()

while not mit.isDone():

for uv in uvs:

util2.createFromList(uv , 2)

float2ParamUV = util2.asFloat2Ptr()

try:

mit.getAxisAtUV(normal,uTangent , vTangent , float2ParamUV)

mit.getPointAtUV(pos,float2ParamUV)

#print '+++ +++' , mit.index()

#print list(normal) , list(uTangent) , list(vTangent) , list(pos)

faceIndex = mit.index()

### start to build matrix 

normal.normalize()

### get none shear tangents 

newVTangent = uTangent ^ normal

newUTangent = normal ^ newVTangent

newVTangent.normalize()

newUTangent.normalize()

newUTangent = newUTangent*-1

###### output  ,  return matrixices and faceIndex

### write om matrix , can change axis order here

matrix = om.MMatrix()

for x in xrange(3):

om.MScriptUtil.setDoubleArray(matrix[0], x, newUTangent[x])

om.MScriptUtil.setDoubleArray(matrix[1], x, newVTangent[x])

om.MScriptUtil.setDoubleArray(matrix[2], x, normal[x])

om.MScriptUtil.setDoubleArray(matrix[3], x, pos[x])

outMatrixes.append(matrix)

except:

#print '--- ---' , mit.index()

pass

mit.next()

###





### test in pymel 

for i in range(outMatrixes.length()):

pmatrix = pm.dt.Matrix(outMatrixes[i])

ll = pm.spaceLocator()

pm.xform(ll,ws = 1 , m = pmatrix)





在 2018年11月21日星期三 UTC+8下午2:19:04,Zhen Huang写道:

zhen huang

unread,
Nov 24, 2018, 9:07:07 AM11/24/18
to Python Programming for Autodesk Maya
Hi , 

I've done for the custom follicle , and found the speed is much slower than maya follicle . 

So I did what @Angelo mentioned method to have another plugin with 3 points orthonormal coordinate . The inputs is 5 , index of A,B,C point and UV , so sad even this simple pure math function can't run faster than maya follicle , 
the frame rate of 3 points method is around 16 fps with 1000 rivets , (I just did crossing from BA and CA , define the U from A to BC , define V from AB to BC , to have the tangent and position , basic simple math operation ).  
and maya follicle in same number is around 60 fps 

What a terrible result that I've done all I can do , please help and discuss if you got anything about this topic .

Thanks ,  

在 2018年11月21日星期三 UTC+8下午11:52:04,zhen huang写道:

Angelo Sta. Catalina

unread,
Nov 24, 2018, 10:30:27 AM11/24/18
to python_in...@googlegroups.com
Did you do that test with a python plugin? It will always be slower then Maya's method. Also, rivets aren't GPU friendly so things are a lot slower

To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/32d4b06e-7f02-4d07-ae88-2830a62a902d%40googlegroups.com.

zhen huang

unread,
Nov 24, 2018, 8:46:47 PM11/24/18
to Python Programming for Autodesk Maya
I test with C++ plugin , I think maya follicle is so great when I had this test .  

在 2018年11月24日星期六 UTC+8下午11:30:27,Angelo写道:
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages