PDA

View Full Version : Maya approach similar to Grasshopper's Component Population On Mesh?


Royalcolornetwork
08-20-2012, 03:49 AM
Hello,

Saw a video recently showcasing the Grasshopper addition to Rhino's ability to do Component Population on a Mesh:

https://vimeo.com/6996063

Wondering if an equivalent - either a script, or another approach, exists in Maya? In short, the process:

1. Takes a base mesh.
2. Replaces each face of that base mesh with one of four more complex pieces of geometry.
3. The clever part is: which of the 4 alternate - and more complex - pieces of geo is subbed in for that particular face is determined by the textured color of that face. For, instance - a red face is replaced by complex geo #1, a blue face is replaces by complex geo #2, etc.
4. Each piece of complex geo is scaled and rotated to perfectly align with the base face.

Nothing special about the number 4 - ideally, would be an arbitrary number of substitution options. Any way to do this in Maya?

Thanks again!

mfg
08-20-2012, 09:10 AM
yes you can do this in maya very easily. I find the easiest way is to write a script that executes once and populates your nubrs surface, but you can also make it node based so any update to your component will immediately be reflected. Most node that you will need already exist but if you need to write acustom node python would be a big help.

for the most basic version have a look at the following:

pointOnSurface (to divide your nubs and get world positionand surface normals)
colorAtPoint (to get the color value from your nubs surface)
blendshape (for morphing your component based on colorvalue)
lattice (for moving the component to your nurbs surface)

instead of using lattice I prefer working in u,v,normal space on the nurbs but lattice will give you quick results.

Royalcolornetwork
08-21-2012, 01:44 AM
These are great pointers - thank you for the feedback!

Royalcolornetwork
08-21-2012, 02:14 AM
Hi,

Just one more followup question about colorAtPoint - if you have a vertex position on a mesh - which is what it seems like you would be iterating though in this approach - how would you use colorAtPoint to discover the RGB value of the texture at the UV coordinate that corresponds that at vertex position? To put it another way, how to you go from the XYZ position of a vertex on a mesh to the equivalent UV required to query a texture with colorAtPoint?

Thanks again!

mfg
08-21-2012, 10:17 AM
Ah sorry you want to populate a polymesh. Then I would use “paintvertex color tool” to create the gradient on the mesh where u want it and to query the color using “polyColorPerVertex” . You can use this command to query the face color as well not just the vtx like so in python:

mc.polyColorPerVertex('pSphere1.f[236]',q=True,rgb=True)


or you can use this def i wrote in python using api that returns:
vtx ID order per face ,vtx normal, vtx position , face color





import maya.cmds as mc

import maya.OpenMaya as om


def myPolyInfo(polyMesh):

selection = om.MSelectionList()

selection.add(polyMesh)

iter = om.MItSelectionList (selection, om.MFn.kMesh)

myIdList=[]

myVtxNormList=[]

myPointsList=[]

myColorList=[]

myReturnList=[]

#iter through polygons

while not iter.isDone():

dagPath = om.MDagPath()

component = om.MObject()

iter.getDagPath(dagPath, component)

polyIter = om.MItMeshPolygon(dagPath, component)

#iter through faces

while not polyIter.isDone():

i = 0

i = polyIter.index()

#vtx ids in order

vtxIDs = om.MIntArray()

polyIter.getVertices(vtxIDs)

myVtxIdList=[]

for x in range(vtxIDs.length()):

myVtxIdList.append(vtxIDs[x])

myIdList.append(myVtxIdList)

#vtx normals per face

VtxNormList=[]

vtxNormArray = om.MVectorArray()

polyIter.getNormals(vtxNormArray,om.MSpace.kWorld)

for x in range(vtxNormArray.length()):

VtxNormList.append([vtxNormArray[x].x,vtxNormArray[x].y,vtxNormArray[x].z])

myVtxNormList .append(VtxNormList)

#vtx position

PointsList=[]

pointsArray = om.MPointArray()

polyIter.getPoints(pointsArray,om.MSpace.kWorld)

for x in range(pointsArray.length()):

PointsList.append([pointsArray[x][0],pointsArray[x][1],pointsArray[x][2]])

myPointsList.append(PointsList)

#face color

mycolor = om.MColor()

polyIter.getColor(mycolor)

myColorList.append([mycolor[0],mycolor[1],mycolor[2]])

polyIter.next()

iter.next()

#all results:

myReturnList.extend([myIdList])

myReturnList.extend([myVtxNormList])

myReturnList.extend([myPointsList])

myReturnList.extend([myColorList])


return myReturnList


#=================================================================================================

selection=mc.ls(sl=True,fl=True)

Info=myPolyInfo(selection[0])

IDs=Info[0]

Norm=Info[1]

Points=Info[2]

Color=Info[3]


print IDs

print Norm

print Points

print Color

#print len(IDs)

#print len(Norm)

#print len(Points)



PS : Pasting code to the forum seems broken, what am i doing wrong

Royalcolornetwork
08-22-2012, 03:52 AM
Thank you!

CGTalk Moderation
08-22-2012, 03:52 AM
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.