Ejemplo n.º 1
0
def GetFacesByBitmapMask(shape, bitmapMaskPath):
    file_node = cmds.shadingNode("file", asTexture=True)
    cmds.setAttr('%s.fileTextureName' % file_node,
                 bitmapMaskPath,
                 type="string")
    cmds.select(clear=True)

    all_faces = cmds.filterExpand(cmds.polyListComponentConversion(
        shape, toFace=True),
                                  sm=34,
                                  expand=True)
    matched_faces = []

    for f in all_faces:
        center = GetFaceUVCenter(
            f)  # !!! VERY SLOW !!! Can be optimized with maya.OpenMaya
        alpha = 0.0
        try:
            alpha = cmds.colorAtPoint(
                file_node, u=center[0],
                v=center[1])  #return array with one element
            alpha = alpha[0]
            #print alpha
        except BaseException:
            pass

        if alpha > 0.6:
            matched_faces.append(f)
    cmds.delete(file_node)
    cmds.select(clear=True)
    return matched_faces
Ejemplo n.º 2
0
    def w05_filterByMap(self, mapObj, map, objects, *args):
        if isinstance( objects, str) or isinstance( objects, unicode):
            objects = [objects]
            
        if cmds.pluginInfo("nearestPointOnMesh",query=True,l=True)==False:
            cmds.loadPlugin("nearestPointOnMesh")
        
        uvNode = ''     
        for node in cmds.listConnections('%s.worldMesh'%(mapObj), s=False):
            if cmds.objectType(node) == 'nearestPointOnMesh' and cmds.listConnections(node+'.inPosition') == None:
                uvNode = node
                break
        if uvNode == '':
            uvNode = cmds.createNode("nearestPointOnMesh", n="mapUV")
            cmds.connectAttr(mapObj+'.worldMesh[0]', uvNode+'.inMesh',f=True)
        
        data = {}
        for object in objects:     
            objPos=cmds.objectCenter(object)
            cmds.setAttr(uvNode+'.inPosition', objPos[0], objPos[1], objPos[2], type="double3")
            atu = cmds.getAttr(uvNode+'.parameterU')
            atv = cmds.getAttr(uvNode+'.parameterV')
            
            
            rgb = cmds.colorAtPoint(map, o='RGB', u=atu, v=atv)
            value = mel.eval('rgb_to_hsv <<%s, %s, %s>>'%(rgb[0], rgb[1], rgb[2]) )[2]
            data[object]=(value)
        return data

#w05_selectByMapWin()
Ejemplo n.º 3
0
def surfaceColorAtPoint( surfaceNode, position ):
    
    import sgBFunction_dag
    
    def getCloseNode( surfaceNode ):
        closeNode = cmds.listConnections( surfaceNode+'.worldSpace', type='closestPointOnSurface' )
        if closeNode: return closeNode[0]
        closeNode = cmds.createNode( 'closestPointOnSurface' )
        cmds.connectAttr( surfaceNode+'.worldSpace', closeNode+'.inputSurface' )
        return closeNode
    
    surfaceNode = sgBFunction_dag.getShape( surfaceNode )
    closeNode = getCloseNode( surfaceNode )
    cmds.setAttr( closeNode+'.inPosition', *position )
    
    shadingEngines = sgBFunction_dag.getShadingEngines( surfaceNode )
    if not shadingEngines: return None
    
    shader = cmds.listConnections( shadingEngines[0]+'.surfaceShader', s=1, d=0 )
    texture = cmds.listConnections( shader[0]+'.color', s=1, d=0 )
    
    if not texture: return None
    
    uValue = cmds.getAttr( closeNode+'.parameterU' )
    vValue = cmds.getAttr( closeNode+'.parameterV' )
    
    return cmds.colorAtPoint( texture[0], u=uValue, v=vValue )
Ejemplo n.º 4
0
def surfaceColorAtPoint(surfaceNode, position):

    import sgBFunction_dag

    def getCloseNode(surfaceNode):
        closeNode = cmds.listConnections(surfaceNode + '.worldSpace',
                                         type='closestPointOnSurface')
        if closeNode: return closeNode[0]
        closeNode = cmds.createNode('closestPointOnSurface')
        cmds.connectAttr(surfaceNode + '.worldSpace',
                         closeNode + '.inputSurface')
        return closeNode

    surfaceNode = sgBFunction_dag.getShape(surfaceNode)
    closeNode = getCloseNode(surfaceNode)
    cmds.setAttr(closeNode + '.inPosition', *position)

    shadingEngines = sgBFunction_dag.getShadingEngines(surfaceNode)
    if not shadingEngines: return None

    shader = cmds.listConnections(shadingEngines[0] + '.surfaceShader',
                                  s=1,
                                  d=0)
    texture = cmds.listConnections(shader[0] + '.color', s=1, d=0)

    if not texture: return None

    uValue = cmds.getAttr(closeNode + '.parameterU')
    vValue = cmds.getAttr(closeNode + '.parameterV')

    return cmds.colorAtPoint(texture[0], u=uValue, v=vValue)
def testColorAtPoint():
    # per testare questa funzione seleziona la mesh nel suo intero in object mode
    txtName = getTexture()
    colors = cmd.colorAtPoint(txtName,
                              o='RGB',
                              su=16,
                              sv=16,
                              mu=0.0,
                              mv=0.0,
                              xu=0.5,
                              xv=0.5)
    print colors
Ejemplo n.º 6
0
def getSurfaceColorValues( point, surf ):
    
    closeSurf = cmds.createNode( 'closestPointOnSurface' )
    surfShape = cmds.listRelatives( surf, s=1 )[0]
    shadingEngins = cmds.listConnections( surfShape+'.instObjGroups[0]' )
    engin = shadingEngins[0]
    
    shaders = cmds.listConnections( engin+'.surfaceShader' )
    
    textures = cmds.listConnections( shaders[0]+'.color' )
    
    cmds.connectAttr( surfShape+'.worldSpace', closeSurf+'.inputSurface' )
    
    cmds.setAttr( closeSurf+'.inPosition', *point )

    colors = cmds.colorAtPoint( textures[0], u=cmds.getAttr( closeSurf+'.u' ),
                                            v=cmds.getAttr( closeSurf+'.v' ) )

    return colors
Ejemplo n.º 7
0
def getSurfaceColorValues( objs, surf ):
    
    closeSurf = cmds.createNode( 'closestPointOnSurface' )
    surfShape = cmds.listRelatives( surf, s=1 )[0]
    shadingEngins = cmds.listConnections( surfShape+'.instObjGroups[0]' )
    engin = shadingEngins[0]
    
    shaders = cmds.listConnections( engin+'.surfaceShader' )
    
    textures = cmds.listConnections( shaders[0]+'.color' )
    
    cmds.connectAttr( surfShape+'.worldSpace', closeSurf+'.inputSurface' )
    
    colorValues = []
    minValue = 2.0
    maxValue = -1.0
    for obj in objs:
        dcmp = cmds.createNode( 'decomposeMatrix' )
        
        cmds.setAttr( dcmp+'.imat', cmds.getAttr( obj+'.wm' ), type='matrix' )
        cmds.setAttr( closeSurf+'.inPosition', *cmds.getAttr( dcmp+'.ot' )[0] )
    
        colors = cmds.colorAtPoint( textures[0], u=cmds.getAttr( closeSurf+'.u' ),
                                                v=cmds.getAttr( closeSurf+'.v' ) )
        value = 0.0
        for color in colors:
            value += color
        value /= len( colors )
        
        if value > maxValue:
            maxValue = value
        if value < minValue:
            minValue = value
        
        colorValues.append( value )
        
    cmds.delete( closeSurf )
    
    return colorValues, minValue, maxValue
def main():
    rgb = pickColor()
    uvList = getUV()
    faceList = getFaces()

    # null starting values should be left at 1
    coordCount = 1

    # selct the geometry & get the number of coords to check
    cmds.select(geometryName[0])
    coords = cmds.polyEvaluate(uv=True)


    selectedUVs  = []
    compareUVs = []
    picked = []
    
    # for each UV coordinate found
    for uv in uvList:

        # define inital values for selected color from color picker
        r = 0.0
        b = 0.0
        g = 0.0

        # define rgb values from each uv coord
        rPick = rgb[0]
        gPick = rgb[1]
        bPick = rgb[2]        

        # if the coord count is NOT equal to the total number of coords to check...keep checking
        if coordCount != coords:

            # get the float rgb values for each color coord
            rSample = cmds.colorAtPoint(str(textureName[0]), o='RGB',u=uv[0], v=uv[1])[0]
            gSample = cmds.colorAtPoint(str(textureName[0]), o='RGB',u=uv[0], v=uv[1])[1]
            bSample = cmds.colorAtPoint(str(textureName[0]), o='RGB',u=uv[0], v=uv[1])[2]

            # round values and convert to 0 to 255
            rPoint = round(rSample * 255)
            gPoint = round(gSample * 255)
            bPoint = round(bSample * 255)

            # print the coord that is currently being checked

            # subtract the coord from the total coords to get the remaining
            coordRemain = int(coords) - 1            

            # compare coord color to picked color
            if rPoint == rPick and gPoint == gPick and bPoint == bPick:
                # if the color matches, add the uv coord to the list of selected
                # if the coord color value matches the picked value, add the coorffd to the selected uv list
                selectedUVs.append(uv)

            # if the coord count is not yet equal to the total number of coords, continue processing coords
            if coordCount != coords:
                # add 1 to the total completed
                coordCount += 1
                # print the percentage remaining
                complete = float(coordCount) / float(coords) * float(100)
                remaining = float(100)-complete
                rounded = round(remaining)

                if rounded < 1:
                    print ('finishing')
                else:
                    print (str(rounded) +'% remaining')

            # if the coordCount becomes equal to the number of coords, compare each list
            if coordCount == coords:
                # get the bounding box for the list of all the faces in geometry
                for bounds in faceList[0]:
                    xFace = bounds[0]
                    yFace = bounds[1]                        
                    xFaceMin = xFace[0]
                    xFaceMax = xFace[1]
                    yFaceMin = yFace[0]
                    yFaceMax = yFace[1]                  
                    
                    # we have a list of uvs with the color selected
                    for youvee in selectedUVs:
                        # now we need to compare each colored uv location with the face bounding boxes.
                        if xFaceMin <= youvee[0] <= xFaceMax and yFaceMin <= youvee[1] <= yFaceMax:
                                compareUVs.append(youvee)
                                
                # we lost the name of the face when comparing the matched uv with the bounds of the face.
                # we get the matched uv list and recheck it against the face bounds and then select the face.
                for i in compareUVs:
                    xUV = i[0]
                    yUV = i[1]                                       
                
                    for face in faceList[1]:
                        cmds.select(face)
                        boundsCheck = cmds.polyEvaluate(bc2=True)
                        xFace = boundsCheck[0]
                        yFace = boundsCheck[1]                        
                        xFaceMin = xFace[0]
                        xFaceMax = xFace[1]
                        yFaceMin = yFace[0]
                        yFaceMax = yFace[1]
                        
                        if xFaceMin <= xUV <= xFaceMax and yFaceMin <= yUV <= yFaceMax:
                            # if the UV bounds falls inside of the Facebounds, append the face to the picked list
                            picked.append(face)
                            
            # print the picked list, and select each face inside of it.
            print 'picked = ' + str(picked)
            for p in picked:
                cmds.polyCut(p)
Ejemplo n.º 9
0
	def createVoxelMesh(self, voxelCenterPosition,uvArray,texNodeName,cubeWidth,outputMeshData):
		numVoxels = len(voxelCenterPosition)
		numVertices = 8														#number of vertices
		numPolygons = 6 													#number of polygons
		numVerticesPerPolygon = 4     										#number of vertices per polygon
		numNormalsPerVoxel = numVerticesPerPolygon * numPolygons 			#24 number of vertex normals
		numPolygonConnectsPerVoxel = numPolygons * numVerticesPerPolygon 	#24 number of polygon connects
		cubeHalfWidth = cubeWidth/2
		#initialize all the params in the MFnMesh.create()
		#vertexArray: point array, This should include all the vertices in the mesh and no eatras
		totalVertices = numVertices * numVoxels
		vertexArray =OpenMaya.MFloatPointArray()
		#polygonCounts array of vertex counts for each polygon
		#for the cube would have 6 faces, each of which had 4 verts, so the polygonCounts would be [4,4,4,4,4,4]
		totalPolygons = numPolygons * numVoxels
		polygonCounts = OpenMaya.MIntArray()
		#polygonConnects 
		#array of vertex connections for each polygon
		polygonConnects = OpenMaya.MIntArray()
		#set shared Normals for these vertices
		vertexNormals = OpenMaya.MVectorArray()
		#vertexColorArray
		vertexColorArray = OpenMaya.MColorArray()
		#vertexColorIndexArray
		vertexIndexArray = OpenMaya.MIntArray()
		#PolygonIDArray
		faceList = OpenMaya.MIntArray()

		for i in range (numVoxels):
			pVoxelCenterPosition = voxelCenterPosition[i]
			#Update VertexArray for VoxelMesh
			vertexList = [	OpenMaya.MFloatPoint(pVoxelCenterPosition.x-cubeHalfWidth, pVoxelCenterPosition.y-cubeHalfWidth, pVoxelCenterPosition.z-cubeHalfWidth), #vertex 0 
							OpenMaya.MFloatPoint(pVoxelCenterPosition.x-cubeHalfWidth, pVoxelCenterPosition.y-cubeHalfWidth, pVoxelCenterPosition.z+cubeHalfWidth), #vertex 1
							OpenMaya.MFloatPoint(pVoxelCenterPosition.x-cubeHalfWidth, pVoxelCenterPosition.y+cubeHalfWidth, pVoxelCenterPosition.z-cubeHalfWidth), #vertex 2
							OpenMaya.MFloatPoint(pVoxelCenterPosition.x-cubeHalfWidth, pVoxelCenterPosition.y+cubeHalfWidth, pVoxelCenterPosition.z+cubeHalfWidth), #vertex 3
							OpenMaya.MFloatPoint(pVoxelCenterPosition.x+cubeHalfWidth, pVoxelCenterPosition.y-cubeHalfWidth, pVoxelCenterPosition.z-cubeHalfWidth), #vertex 4
							OpenMaya.MFloatPoint(pVoxelCenterPosition.x+cubeHalfWidth, pVoxelCenterPosition.y-cubeHalfWidth, pVoxelCenterPosition.z+cubeHalfWidth), #vertex 5
							OpenMaya.MFloatPoint(pVoxelCenterPosition.x+cubeHalfWidth, pVoxelCenterPosition.y+cubeHalfWidth, pVoxelCenterPosition.z-cubeHalfWidth), #vertex 6
							OpenMaya.MFloatPoint(pVoxelCenterPosition.x+cubeHalfWidth, pVoxelCenterPosition.y+cubeHalfWidth, pVoxelCenterPosition.z+cubeHalfWidth), #vertex 7
						 ]

			for j in range (numVertices):
				vertexArray.append(vertexList[j])
				#here need to assign vertex color
				if texNodeName:
					vertexColor = cmds.colorAtPoint(texNodeName, o='RGB', u=uvArray[i][0], v=uvArray[i][1])
					mColor = OpenMaya.MColor(vertexColor[0],vertexColor[1],vertexColor[2],1.0)
					vertexColorArray.append(mColor)
					vertexIndexArray.append(i * numVertices + j)
				#print vertexColor

			#Update polygonCounts for VoxelMesh
			for j in range (numPolygons):
				polygonCounts.append(numVerticesPerPolygon)
				faceList.append(i*numPolygons+j)
			#Update polygonConnects for VoxelMesh
			#Update vertexNormals for VoxelMesh
			polygonConnectsList = [	0,1,3,2,
									1,5,7,3,
									4,6,7,5,
									2,6,4,0,
									0,4,5,1,
									2,3,7,6]

			vertexNormalsList = [	OpenMaya.MVector(-1.0,0.0,0.0),   		#vertex normal on face (0,1,3,2) #0
									OpenMaya.MVector(-1.0,0.0,0.0),			#vertex normal on face (0,1,3,2) #1
									OpenMaya.MVector(-1.0,0.0,0.0),			#vertex normal on face (0,1,3,2) #7
									OpenMaya.MVector(-1.0,0.0,0.0),			#vertex normal on face (0,1,3,2) #3

									OpenMaya.MVector(0.0,0.0,1.0),   		#vertex normal on face (1,5,7,3) #1
									OpenMaya.MVector(0.0,0.0,1.0),			#vertex normal on face (1,5,7,3) #5
									OpenMaya.MVector(0.0,0.0,1.0),			#vertex normal on face (1,5,7,3) #7 
									OpenMaya.MVector(0.0,0.0,1.0),			#vertex normal on face (1,5,7,3) #3

									OpenMaya.MVector(1.0,0.0,0.0),   		#vertex normal on face (4,6,7,5) #4
									OpenMaya.MVector(1.0,0.0,0.0),			#vertex normal on face (4,6,7,5) #6
									OpenMaya.MVector(1.0,0.0,0.0),			#vertex normal on face (4,6,7,5) #7
									OpenMaya.MVector(1.0,0.0,0.0),			#vertex normal on face (4,6,7,5) #5

									OpenMaya.MVector(0.0,0.0,-1.0),   		#vertex normal on face (2,6,4,0) #2
									OpenMaya.MVector(0.0,0.0,-1.0),			#vertex normal on face (2,6,4,0) #6
									OpenMaya.MVector(0.0,0.0,-1.0),			#vertex normal on face (2,6,4,0) #4
									OpenMaya.MVector(0.0,0.0,-1.0),			#vertex normal on face (2,6,4,0) #0

									OpenMaya.MVector(0.0,-1.0,0.0),   		#vertex normal on face (0,4,5,1) #0 
									OpenMaya.MVector(0.0,-1.0,0.0),			#vertex normal on face (0,4,5,1) #4
									OpenMaya.MVector(0.0,-1.0,0.0),			#vertex normal on face (0,4,5,1) #5
									OpenMaya.MVector(0.0,-1.0,0.0),			#vertex normal on face (0,4,5,1) #1

									OpenMaya.MVector(0.0,1.0,0.0),   		#vertex normal on face (2,3,7,6) #2
									OpenMaya.MVector(0.0,1.0,0.0),			#vertex normal on face (2,3,7,6) #3
									OpenMaya.MVector(0.0,1.0,0.0),			#vertex normal on face (2,3,7,6) #7
									OpenMaya.MVector(0.0,1.0,0.0)			#vertex normal on face (2,3,7,6) #6
								]			
			for j in range (numNormalsPerVoxel):
				vertexNormals.append(vertexNormalsList[j])
				polygonConnects.append(polygonConnectsList[j] + i * numVertices)
			#for j in range (numPolygonConnectsPerVoxel):



		mFnMesh = OpenMaya.MFnMesh()
		#shapeNode
		mMeshShape = mFnMesh.create (totalVertices, totalPolygons, vertexArray, polygonCounts, polygonConnects,outputMeshData)
		#mMeshShape --> kMeshGeom
		mCubeMesh = OpenMaya.MFnMesh(mMeshShape)
		'''
		#assign Normal to the Cubes:

		#confused how to use setFaceVertexNormals
		#rewrite the function for setFaceVertexNormals based on setFaceVertexNormal
		#by query the facelist
		#support hard edge!

		for i in range (faceList.length()):
			for j in range (numVerticesPerPolygon):
				index = numVerticesPerPolygon * i + j
				mCubeMesh.setFaceVertexNormal(vertexNormals[index], i, polygonConnects[index])
		'''
		#'''
		#setVertexColor
		if texNodeName:
			mCubeMesh.createColorSetDataMesh('vertexColorSet')
			mCubeMesh.setVertexColors(vertexColorArray, vertexIndexArray, None, OpenMaya.MFnMesh.kRGBA)
		#'''

		return outputMeshData
Ejemplo n.º 10
0
    #colorVertex = cmds.polyColorPerVertex(vertices, q=1,b=1)

    uv = cmds.polyListComponentConversion(closestVertice, fv=True, tuv=True)

    cmds.pointPosition(uv[0])
    uvCoord = cmds.polyEditUV(uv[0], query=True, u=True, v=True)

    # get shapes of selection:
    shapesInSel = cmds.ls(dag=1, o=1, s=1, sl=1)
    # get shading groups from shapes:
    shadingGrps = cmds.listConnections(shapesInSel, type='shadingEngine')
    # get the shaders:
    shaders = cmds.ls(cmds.listConnections(shadingGrps), materials=1)
    textureName = cmds.listConnections(shaders[0] + ".color")[0]
    colorVertex = cmds.colorAtPoint(textureName,
                                    o='RGB',
                                    u=uvCoord[0],
                                    v=uvCoord[1])

    #mel.eval("polyColorPerVertex -q -g -b")

    cmds.select(name)
    return colorVertex


#colorClosestVertex(0,0,0)


def show():

    #indice et noms couleurs
    clr = ["Red", "Blue", "Green", "Yellow", "Orange"]
Ejemplo n.º 11
0
    def createVoxelMesh(self, voxelCenterPosition, uvArray, texNodeName,
                        cubeWidth, outputMeshData):
        numVoxels = len(voxelCenterPosition)
        numVertices = 8  #number of vertices
        numPolygons = 6  #number of polygons
        numVerticesPerPolygon = 4  #number of vertices per polygon
        numNormalsPerVoxel = numVerticesPerPolygon * numPolygons  #24 number of vertex normals
        numPolygonConnectsPerVoxel = numPolygons * numVerticesPerPolygon  #24 number of polygon connects
        cubeHalfWidth = cubeWidth / 2
        #initialize all the params in the MFnMesh.create()
        #vertexArray: point array, This should include all the vertices in the mesh and no eatras
        totalVertices = numVertices * numVoxels
        vertexArray = OpenMaya.MFloatPointArray()
        #polygonCounts array of vertex counts for each polygon
        #for the cube would have 6 faces, each of which had 4 verts, so the polygonCounts would be [4,4,4,4,4,4]
        totalPolygons = numPolygons * numVoxels
        polygonCounts = OpenMaya.MIntArray()
        #polygonConnects
        #array of vertex connections for each polygon
        polygonConnects = OpenMaya.MIntArray()
        #set shared Normals for these vertices
        vertexNormals = OpenMaya.MVectorArray()
        #vertexColorArray
        vertexColorArray = OpenMaya.MColorArray()
        #vertexColorIndexArray
        vertexIndexArray = OpenMaya.MIntArray()
        #PolygonIDArray
        faceList = OpenMaya.MIntArray()

        for i in range(numVoxels):
            pVoxelCenterPosition = voxelCenterPosition[i]
            #Update VertexArray for VoxelMesh
            vertexList = [
                OpenMaya.MFloatPoint(pVoxelCenterPosition.x - cubeHalfWidth,
                                     pVoxelCenterPosition.y - cubeHalfWidth,
                                     pVoxelCenterPosition.z -
                                     cubeHalfWidth),  #vertex 0 
                OpenMaya.MFloatPoint(pVoxelCenterPosition.x - cubeHalfWidth,
                                     pVoxelCenterPosition.y - cubeHalfWidth,
                                     pVoxelCenterPosition.z +
                                     cubeHalfWidth),  #vertex 1
                OpenMaya.MFloatPoint(pVoxelCenterPosition.x - cubeHalfWidth,
                                     pVoxelCenterPosition.y + cubeHalfWidth,
                                     pVoxelCenterPosition.z -
                                     cubeHalfWidth),  #vertex 2
                OpenMaya.MFloatPoint(pVoxelCenterPosition.x - cubeHalfWidth,
                                     pVoxelCenterPosition.y + cubeHalfWidth,
                                     pVoxelCenterPosition.z +
                                     cubeHalfWidth),  #vertex 3
                OpenMaya.MFloatPoint(pVoxelCenterPosition.x + cubeHalfWidth,
                                     pVoxelCenterPosition.y - cubeHalfWidth,
                                     pVoxelCenterPosition.z -
                                     cubeHalfWidth),  #vertex 4
                OpenMaya.MFloatPoint(pVoxelCenterPosition.x + cubeHalfWidth,
                                     pVoxelCenterPosition.y - cubeHalfWidth,
                                     pVoxelCenterPosition.z +
                                     cubeHalfWidth),  #vertex 5
                OpenMaya.MFloatPoint(pVoxelCenterPosition.x + cubeHalfWidth,
                                     pVoxelCenterPosition.y + cubeHalfWidth,
                                     pVoxelCenterPosition.z -
                                     cubeHalfWidth),  #vertex 6
                OpenMaya.MFloatPoint(pVoxelCenterPosition.x + cubeHalfWidth,
                                     pVoxelCenterPosition.y + cubeHalfWidth,
                                     pVoxelCenterPosition.z +
                                     cubeHalfWidth),  #vertex 7
            ]

            for j in range(numVertices):
                vertexArray.append(vertexList[j])
                #here need to assign vertex color
                if texNodeName:
                    vertexColor = cmds.colorAtPoint(texNodeName,
                                                    o='RGB',
                                                    u=uvArray[i][0],
                                                    v=uvArray[i][1])
                    mColor = OpenMaya.MColor(vertexColor[0], vertexColor[1],
                                             vertexColor[2], 1.0)
                    vertexColorArray.append(mColor)
                    vertexIndexArray.append(i * numVertices + j)
                #print vertexColor

            #Update polygonCounts for VoxelMesh
            for j in range(numPolygons):
                polygonCounts.append(numVerticesPerPolygon)
                faceList.append(i * numPolygons + j)
            #Update polygonConnects for VoxelMesh
            #Update vertexNormals for VoxelMesh
            polygonConnectsList = [
                0, 1, 3, 2, 1, 5, 7, 3, 4, 6, 7, 5, 2, 6, 4, 0, 0, 4, 5, 1, 2,
                3, 7, 6
            ]

            vertexNormalsList = [
                OpenMaya.MVector(-1.0, 0.0,
                                 0.0),  #vertex normal on face (0,1,3,2) #0
                OpenMaya.MVector(-1.0, 0.0,
                                 0.0),  #vertex normal on face (0,1,3,2) #1
                OpenMaya.MVector(-1.0, 0.0,
                                 0.0),  #vertex normal on face (0,1,3,2) #7
                OpenMaya.MVector(-1.0, 0.0,
                                 0.0),  #vertex normal on face (0,1,3,2) #3
                OpenMaya.MVector(0.0, 0.0,
                                 1.0),  #vertex normal on face (1,5,7,3) #1
                OpenMaya.MVector(0.0, 0.0,
                                 1.0),  #vertex normal on face (1,5,7,3) #5
                OpenMaya.MVector(0.0, 0.0,
                                 1.0),  #vertex normal on face (1,5,7,3) #7 
                OpenMaya.MVector(0.0, 0.0,
                                 1.0),  #vertex normal on face (1,5,7,3) #3
                OpenMaya.MVector(1.0, 0.0,
                                 0.0),  #vertex normal on face (4,6,7,5) #4
                OpenMaya.MVector(1.0, 0.0,
                                 0.0),  #vertex normal on face (4,6,7,5) #6
                OpenMaya.MVector(1.0, 0.0,
                                 0.0),  #vertex normal on face (4,6,7,5) #7
                OpenMaya.MVector(1.0, 0.0,
                                 0.0),  #vertex normal on face (4,6,7,5) #5
                OpenMaya.MVector(0.0, 0.0,
                                 -1.0),  #vertex normal on face (2,6,4,0) #2
                OpenMaya.MVector(0.0, 0.0,
                                 -1.0),  #vertex normal on face (2,6,4,0) #6
                OpenMaya.MVector(0.0, 0.0,
                                 -1.0),  #vertex normal on face (2,6,4,0) #4
                OpenMaya.MVector(0.0, 0.0,
                                 -1.0),  #vertex normal on face (2,6,4,0) #0
                OpenMaya.MVector(0.0, -1.0,
                                 0.0),  #vertex normal on face (0,4,5,1) #0 
                OpenMaya.MVector(0.0, -1.0,
                                 0.0),  #vertex normal on face (0,4,5,1) #4
                OpenMaya.MVector(0.0, -1.0,
                                 0.0),  #vertex normal on face (0,4,5,1) #5
                OpenMaya.MVector(0.0, -1.0,
                                 0.0),  #vertex normal on face (0,4,5,1) #1
                OpenMaya.MVector(0.0, 1.0,
                                 0.0),  #vertex normal on face (2,3,7,6) #2
                OpenMaya.MVector(0.0, 1.0,
                                 0.0),  #vertex normal on face (2,3,7,6) #3
                OpenMaya.MVector(0.0, 1.0,
                                 0.0),  #vertex normal on face (2,3,7,6) #7
                OpenMaya.MVector(0.0, 1.0,
                                 0.0)  #vertex normal on face (2,3,7,6) #6
            ]
            for j in range(numNormalsPerVoxel):
                vertexNormals.append(vertexNormalsList[j])
                polygonConnects.append(polygonConnectsList[j] +
                                       i * numVertices)
            #for j in range (numPolygonConnectsPerVoxel):

        mFnMesh = OpenMaya.MFnMesh()
        #shapeNode
        mMeshShape = mFnMesh.create(totalVertices, totalPolygons, vertexArray,
                                    polygonCounts, polygonConnects,
                                    outputMeshData)
        #mMeshShape --> kMeshGeom
        mCubeMesh = OpenMaya.MFnMesh(mMeshShape)
        '''
		#assign Normal to the Cubes:

		#confused how to use setFaceVertexNormals
		#rewrite the function for setFaceVertexNormals based on setFaceVertexNormal
		#by query the facelist
		#support hard edge!

		for i in range (faceList.length()):
			for j in range (numVerticesPerPolygon):
				index = numVerticesPerPolygon * i + j
				mCubeMesh.setFaceVertexNormal(vertexNormals[index], i, polygonConnects[index])
		'''
        #'''
        #setVertexColor
        if texNodeName:
            mCubeMesh.createColorSetDataMesh('vertexColorSet')
            mCubeMesh.setVertexColors(vertexColorArray, vertexIndexArray, None,
                                      OpenMaya.MFnMesh.kRGBA)
        #'''

        return outputMeshData
Ejemplo n.º 12
0
    def createVoxelMesh(self, voxelCenterPosition, uvArray, texNodeName,
                        cubeWidth, voxelWeights, voxelBlendWeights):
        numVoxels = len(voxelCenterPosition)
        numVertices = 8  #number of vertices
        numPolygons = 6  #number of polygons
        numVerticesPerPolygon = 4  #number of vertices per polygon
        numNormalsPerVoxel = numVerticesPerPolygon * numPolygons  #24 number of vertex normals
        numPolygonConnectsPerVoxel = numPolygons * numVerticesPerPolygon  #24 number of polygon connects
        cubeHalfWidth = cubeWidth / 2.0
        #initialize all the params in the MFnMesh.create()
        #vertexArray: point array, This should include all the vertices in the mesh and no eatras
        totalVertices = numVertices * numVoxels
        vertexArray = OpenMaya.MFloatPointArray()
        #polygonCounts array of vertex counts for each polygon
        #for the cube would have 6 faces, each of which had 4 verts, so the polygonCounts would be [4,4,4,4,4,4]
        totalPolygons = numPolygons * numVoxels
        polygonCounts = OpenMaya.MIntArray()
        #polygonConnects
        #array of vertex connections for each polygon
        polygonConnects = OpenMaya.MIntArray()
        #set shared Normals for these vertices
        vertexNormals = OpenMaya.MVectorArray()
        #vertexColorArray
        vertexColorArray = OpenMaya.MColorArray()
        #vertexColorIndexArray
        vertexIndexArray = OpenMaya.MIntArray()
        #PolygonIDArray
        faceList = OpenMaya.MIntArray()
        #vertexWeightArray
        vertexWeightArray = OpenMaya.MDoubleArray()
        #vertexBlendWeightArray
        vertexBlendWeightArray = OpenMaya.MDoubleArray()

        for i in range(numVoxels):
            pVoxelCenterPosition = voxelCenterPosition[i]
            #Update VertexArray for VoxelMesh
            vertexList = [
                OpenMaya.MFloatPoint(pVoxelCenterPosition.x - cubeHalfWidth,
                                     pVoxelCenterPosition.y - cubeHalfWidth,
                                     pVoxelCenterPosition.z -
                                     cubeHalfWidth),  #vertex 0 
                OpenMaya.MFloatPoint(pVoxelCenterPosition.x - cubeHalfWidth,
                                     pVoxelCenterPosition.y - cubeHalfWidth,
                                     pVoxelCenterPosition.z +
                                     cubeHalfWidth),  #vertex 1
                OpenMaya.MFloatPoint(pVoxelCenterPosition.x - cubeHalfWidth,
                                     pVoxelCenterPosition.y + cubeHalfWidth,
                                     pVoxelCenterPosition.z -
                                     cubeHalfWidth),  #vertex 2
                OpenMaya.MFloatPoint(pVoxelCenterPosition.x - cubeHalfWidth,
                                     pVoxelCenterPosition.y + cubeHalfWidth,
                                     pVoxelCenterPosition.z +
                                     cubeHalfWidth),  #vertex 3
                OpenMaya.MFloatPoint(pVoxelCenterPosition.x + cubeHalfWidth,
                                     pVoxelCenterPosition.y - cubeHalfWidth,
                                     pVoxelCenterPosition.z -
                                     cubeHalfWidth),  #vertex 4
                OpenMaya.MFloatPoint(pVoxelCenterPosition.x + cubeHalfWidth,
                                     pVoxelCenterPosition.y - cubeHalfWidth,
                                     pVoxelCenterPosition.z +
                                     cubeHalfWidth),  #vertex 5
                OpenMaya.MFloatPoint(pVoxelCenterPosition.x + cubeHalfWidth,
                                     pVoxelCenterPosition.y + cubeHalfWidth,
                                     pVoxelCenterPosition.z -
                                     cubeHalfWidth),  #vertex 6
                OpenMaya.MFloatPoint(pVoxelCenterPosition.x + cubeHalfWidth,
                                     pVoxelCenterPosition.y + cubeHalfWidth,
                                     pVoxelCenterPosition.z +
                                     cubeHalfWidth),  #vertex 7
            ]

            for j in range(numVertices):
                vertexArray.append(vertexList[j])
                #here need to assign vertexWeight
                if self.skinCluster:
                    for item in voxelWeights[i]:
                        vertexWeightArray.append(item)
                    vertexBlendWeightArray.append(voxelBlendWeights[i])
                    #print [item for sublist in voxelWeights[i] for item in sublist]
                #here need to assign vertex color
                if texNodeName:
                    vertexColor = cmds.colorAtPoint(texNodeName,
                                                    o='RGB',
                                                    u=uvArray[i][0],
                                                    v=uvArray[i][1])
                    mColor = OpenMaya.MColor(vertexColor[0], vertexColor[1],
                                             vertexColor[2])
                    vertexColorArray.append(mColor)
                    vertexIndexArray.append(i * numVertices + j)
                #print vertexColor

            #Update polygonCounts for VoxelMesh
            for j in range(numPolygons):
                polygonCounts.append(numVerticesPerPolygon)
                faceList.append(i * numPolygons + j)
            #Update polygonConnects for VoxelMesh
            #Update vertexNormals for VoxelMesh
            polygonConnectsList = [
                0, 1, 3, 2, 1, 5, 7, 3, 4, 6, 7, 5, 2, 6, 4, 0, 0, 4, 5, 1, 2,
                3, 7, 6
            ]

            vertexNormalsList = [
                OpenMaya.MVector(-1.0, 0.0,
                                 0.0),  #vertex normal on face (0,1,3,2) #0
                OpenMaya.MVector(-1.0, 0.0,
                                 0.0),  #vertex normal on face (0,1,3,2) #1
                OpenMaya.MVector(-1.0, 0.0,
                                 0.0),  #vertex normal on face (0,1,3,2) #7
                OpenMaya.MVector(-1.0, 0.0,
                                 0.0),  #vertex normal on face (0,1,3,2) #3
                OpenMaya.MVector(0.0, 0.0,
                                 1.0),  #vertex normal on face (1,5,7,3) #1
                OpenMaya.MVector(0.0, 0.0,
                                 1.0),  #vertex normal on face (1,5,7,3) #5
                OpenMaya.MVector(0.0, 0.0,
                                 1.0),  #vertex normal on face (1,5,7,3) #7 
                OpenMaya.MVector(0.0, 0.0,
                                 1.0),  #vertex normal on face (1,5,7,3) #3
                OpenMaya.MVector(1.0, 0.0,
                                 0.0),  #vertex normal on face (4,6,7,5) #4
                OpenMaya.MVector(1.0, 0.0,
                                 0.0),  #vertex normal on face (4,6,7,5) #6
                OpenMaya.MVector(1.0, 0.0,
                                 0.0),  #vertex normal on face (4,6,7,5) #7
                OpenMaya.MVector(1.0, 0.0,
                                 0.0),  #vertex normal on face (4,6,7,5) #5
                OpenMaya.MVector(0.0, 0.0,
                                 -1.0),  #vertex normal on face (2,6,4,0) #2
                OpenMaya.MVector(0.0, 0.0,
                                 -1.0),  #vertex normal on face (2,6,4,0) #6
                OpenMaya.MVector(0.0, 0.0,
                                 -1.0),  #vertex normal on face (2,6,4,0) #4
                OpenMaya.MVector(0.0, 0.0,
                                 -1.0),  #vertex normal on face (2,6,4,0) #0
                OpenMaya.MVector(0.0, -1.0,
                                 0.0),  #vertex normal on face (0,4,5,1) #0 
                OpenMaya.MVector(0.0, -1.0,
                                 0.0),  #vertex normal on face (0,4,5,1) #4
                OpenMaya.MVector(0.0, -1.0,
                                 0.0),  #vertex normal on face (0,4,5,1) #5
                OpenMaya.MVector(0.0, -1.0,
                                 0.0),  #vertex normal on face (0,4,5,1) #1
                OpenMaya.MVector(0.0, 1.0,
                                 0.0),  #vertex normal on face (2,3,7,6) #2
                OpenMaya.MVector(0.0, 1.0,
                                 0.0),  #vertex normal on face (2,3,7,6) #3
                OpenMaya.MVector(0.0, 1.0,
                                 0.0),  #vertex normal on face (2,3,7,6) #7
                OpenMaya.MVector(0.0, 1.0,
                                 0.0)  #vertex normal on face (2,3,7,6) #6
            ]
            for j in range(numNormalsPerVoxel):
                vertexNormals.append(vertexNormalsList[j])
                polygonConnects.append(polygonConnectsList[j] +
                                       i * numVertices)

        mFnMesh = OpenMaya.MFnMesh()
        #shapeNode
        mMeshShape = mFnMesh.create(totalVertices, totalPolygons, vertexArray,
                                    polygonCounts, polygonConnects)
        mDagNode = OpenMaya.MFnDagNode(mMeshShape)
        mDagNode.setName('voxelGeom')
        #in case name existing:
        name = mDagNode.name()
        #print mDagNode.name()
        mDagPath = OpenMaya.MDagPath()
        mDagNode = OpenMaya.MFnDagNode(mDagNode.child(0))
        #print mDagNode.name()
        mDagNode.getPath(mDagPath)
        mCubeMesh = OpenMaya.MFnMesh(mDagPath)
        '''
		#assign Normal to the Cubes:

		#confused how to use setFaceVertexNormals
		#rewrite the function for setFaceVertexNormals based on setFaceVertexNormal
		#by query the facelist
		#support hard edge!

		for i in range (faceList.length()):
			for j in range (numVerticesPerPolygon):
				index = numVerticesPerPolygon * i + j
				mCubeMesh.setFaceVertexNormal(vertexNormals[index], i, polygonConnects[index])
		'''
        #'''
        #setVertexColor
        if texNodeName:
            mCubeMesh.createColorSetWithName('vertexColorSet')
            mCubeMesh.setIsColorClamped('vertexClorSet', True)
            mCubeMesh.setVertexColors(vertexColorArray, vertexIndexArray, None,
                                      OpenMaya.MFnMesh.kRGB)
        #'''
        #create skincluster and remap weightData and blendWeight Data
        if self.skinCluster:
            influenceObj = cmds.skinCluster(q=True, inf=True)
            voxelSkinCluster = cmds.skinCluster(influenceObj,
                                                name,
                                                tsb=2,
                                                nw=2)
            mSelectionlist = OpenMaya.MSelectionList()
            mSelectionlist.add(voxelSkinCluster[0])
            mObj_voxelSkinCluster = OpenMaya.MObject()
            mSelectionlist.getDependNode(0, mObj_voxelSkinCluster)
            mfnSkinCluster = OpenMayaAnim.MFnSkinCluster(mObj_voxelSkinCluster)
            mDagPath, component = self.getSkinClusterData(mfnSkinCluster)
            influenceIndices = OpenMaya.MIntArray()
            for i in xrange(len(influenceObj)):
                influenceIndices.append(i)
            #print voxelWeights
            mfnSkinCluster.setWeights(mDagPath, component, influenceIndices,
                                      vertexWeightArray, False)
            mfnSkinCluster.setBlendWeights(mDagPath, component,
                                           vertexBlendWeightArray)

        #'''
        #--[retrive initialShadingGroup]--#
        mSelectionList = OpenMaya.MSelectionList()
        mSelectionList.add("initialShadingGroup")

        mObject_initShdGrp = OpenMaya.MObject()
        mSelectionList.getDependNode(0, mObject_initShdGrp)
        mFnDependencyNode_initialShadingGroup = OpenMaya.MFnDependencyNode(
            mObject_initShdGrp)
        #mFnDependencyNode_initialShadingGroup.setObject(mObject_initShdGrp)
        #name = mFnDependencyNode_initialShadingGroup.name() # Result: initialShadingGroup, so it ok so far
        fnSet = OpenMaya.MFnSet(mObject_initShdGrp)
        fnSet.addMember(mMeshShape)
Ejemplo n.º 13
0
    #print [randX, randY, randZ]
    cmds.xform(obj, relative=True, t=(randX, randY, randZ)) 
        
        
#More cool shit - make a grid of cubes and drive their y position by the color of the image (U,V) on some texture
import maya.cmds as cmds

#cubes
cubes=[]
grp = cmds.group(empty=True, n="cube_GRP")

for x in range(1,11):
    for z in range(1,11):
        U = 1-(x*0.009)
        V = 1-(z*0.009)
        yVal = cmds.colorAtPoint("checker1", u=U, v=V)[0]
        
        thisCube = cmds.polyCube(n="cube_%d"%(x*z))[0]
        cmds.move(x-5.5,yVal,z-5.5, thisCube, a=True)
        cmds.addAttr(at="float", sn="U", k=True)
        cmds.addAttr(at="float", sn="V", k=True)
        cubes.append(thisCube)
        
        print yVal
        
for cube in cubes:
    cmds.parent(cube, grp)

#Plane
#create a checker pattern on this
#myPlane = cmds.polyPlane(n="imageBase_plane", axis=(0,1,0), w=10, h=10, sx=20, sy=20)  
Ejemplo n.º 14
0
    def reshapeD(*pArgs):
        name = cmds.textField(fileName, q=True, text=True)
        if len(name) > 0:
            try:
                '''The returned amount for smoothing and strength modifier'''
                smooth = cmds.intSliderGrp(smoothSlider, q=True, value=True)
                strength = cmds.intSliderGrp(
                    strengthSlider, q=True, value=True) + 1
                if (smooth > 0):
                    cmds.polySmooth(selection, dv=smooth + 1)
                if (strength == 0):
                    strength = .5
                '''The number of vertices in the selected object'''
                numOfVertex = cmds.polyEvaluate(v=True)
                print('The number of vertices for ' + str(selection[0]) +
                      ' is ' + str(numOfVertex))
                cmds.delete(ch=True)
                '''For each vertex'''
                for i in range(numOfVertex):
                    '''defines the vertex'''
                    vertex = cmds.ls(str(selection[0]) + '.vtx[' + str(i) +
                                     ']',
                                     fl=1)
                    print('Current vertex: ' + str(vertex))
                    '''The location/coordinates of the vertex'''
                    vertexLocation = cmds.pointPosition(vertex)
                    x = vertexLocation[0]
                    y = vertexLocation[1]
                    z = vertexLocation[2]
                    #print('X: '+ str(x))
                    #print('Y: '+ str(y))
                    #print('Z: '+ str(z))
                    '''The UV value of the specific vertex'''
                    UVValues = cmds.polyEditUV(
                        cmds.polyListComponentConversion(vertex, toUV=True)[0],
                        query=True)
                    #print('The UV location ' + str(UVValues))
                    '''Color for the height map of the found vertex'''
                    color = 0
                    color = cmds.colorAtPoint(name,
                                              u=UVValues[0],
                                              v=UVValues[1])
                    #print('color: '+str(color[0]))
                    #print(x+color[0])
                    #print(y+color[0])
                    #print(z+color[0])
                    '''Adjusts the location of the vertex based on the heighmap color 0-1'''
                    cmds.polyMoveVertex(
                        vertex,
                        translate=(x + (x * color[0] * strength),
                                   y + (y * color[0] * strength),
                                   z + (z * color[0] * strength)))
                    #print('.........')
                '''Deletes the history and deletes the UI menu'''
                cmds.delete(ch=True)
                cmds.deleteUI(HeightWindow)

            except:
                cmds.deleteUI(HeightWindow)
                cmds.confirmDialog(
                    title='Incorrect File Name',
                    message='The file name for the material is incorrect',
                    button=['Ok'])
Ejemplo n.º 15
0
def main():
    rgb = pickColor()
    uvList = getUV()
    faceList = getFaces()

    # null starting values should be left at 1
    coordCount = 1

    # selct the geometry & get the number of coords to check
    cmds.select(geometryName[0])
    coords = cmds.polyEvaluate(uv=True)

    selectedUVs = []
    compareUVs = []
    picked = []

    # for each UV coordinate found
    for uv in uvList:

        # define inital values for selected color from color picker
        r = 0.0
        b = 0.0
        g = 0.0

        # define rgb values from each uv coord
        rPick = rgb[0]
        gPick = rgb[1]
        bPick = rgb[2]

        # if the coord count is NOT equal to the total number of coords to check...keep checking
        if coordCount != coords:

            # get the float rgb values for each color coord
            rSample = cmds.colorAtPoint(str(textureName[0]),
                                        o='RGB',
                                        u=uv[0],
                                        v=uv[1])[0]
            gSample = cmds.colorAtPoint(str(textureName[0]),
                                        o='RGB',
                                        u=uv[0],
                                        v=uv[1])[1]
            bSample = cmds.colorAtPoint(str(textureName[0]),
                                        o='RGB',
                                        u=uv[0],
                                        v=uv[1])[2]

            # round values and convert to 0 to 255
            rPoint = round(rSample * 255)
            gPoint = round(gSample * 255)
            bPoint = round(bSample * 255)

            # print the coord that is currently being checked

            # subtract the coord from the total coords to get the remaining
            coordRemain = int(coords) - 1

            # compare coord color to picked color
            if rPoint == rPick and gPoint == gPick and bPoint == bPick:
                # if the color matches, add the uv coord to the list of selected
                # if the coord color value matches the picked value, add the coorffd to the selected uv list
                selectedUVs.append(uv)

            # if the coord count is not yet equal to the total number of coords, continue processing coords
            if coordCount != coords:
                # add 1 to the total completed
                coordCount += 1
                # print the percentage remaining
                complete = float(coordCount) / float(coords) * float(100)
                remaining = float(100) - complete
                rounded = round(remaining)

                if rounded < 1:
                    print('finishing')
                else:
                    print(str(rounded) + '% remaining')

            # if the coordCount becomes equal to the number of coords, compare each list
            if coordCount == coords:
                # get the bounding box for the list of all the faces in geometry
                for bounds in faceList[0]:
                    xFace = bounds[0]
                    yFace = bounds[1]
                    xFaceMin = xFace[0]
                    xFaceMax = xFace[1]
                    yFaceMin = yFace[0]
                    yFaceMax = yFace[1]

                    # we have a list of uvs with the color selected
                    for youvee in selectedUVs:
                        # now we need to compare each colored uv location with the face bounding boxes.
                        if xFaceMin <= youvee[
                                0] <= xFaceMax and yFaceMin <= youvee[
                                    1] <= yFaceMax:
                            compareUVs.append(youvee)

                # we lost the name of the face when comparing the matched uv with the bounds of the face.
                # we get the matched uv list and recheck it against the face bounds and then select the face.
                for i in compareUVs:
                    xUV = i[0]
                    yUV = i[1]

                    for face in faceList[1]:
                        cmds.select(face)
                        boundsCheck = cmds.polyEvaluate(bc2=True)
                        xFace = boundsCheck[0]
                        yFace = boundsCheck[1]
                        xFaceMin = xFace[0]
                        xFaceMax = xFace[1]
                        yFaceMin = yFace[0]
                        yFaceMax = yFace[1]

                        if xFaceMin <= xUV <= xFaceMax and yFaceMin <= yUV <= yFaceMax:
                            # if the UV bounds falls inside of the Facebounds, append the face to the picked list
                            picked.append(face)

            # print the picked list, and select each face inside of it.
            print 'picked = ' + str(picked)
            for p in picked:
                cmds.polyCut(p)
Ejemplo n.º 16
0
	def createVoxelMesh(self,voxelCenterPosition,uvArray,texNodeName,cubeWidth,voxelWeights,voxelBlendWeights):
		numVoxels = len(voxelCenterPosition)
		numVertices = 8														#number of vertices
		numPolygons = 6 													#number of polygons
		numVerticesPerPolygon = 4     										#number of vertices per polygon
		numNormalsPerVoxel = numVerticesPerPolygon * numPolygons 			#24 number of vertex normals
		numPolygonConnectsPerVoxel = numPolygons * numVerticesPerPolygon 	#24 number of polygon connects
		cubeHalfWidth = cubeWidth/2.0
		#initialize all the params in the MFnMesh.create()
		#vertexArray: point array, This should include all the vertices in the mesh and no eatras
		totalVertices = numVertices * numVoxels
		vertexArray =OpenMaya.MFloatPointArray()
		#polygonCounts array of vertex counts for each polygon
		#for the cube would have 6 faces, each of which had 4 verts, so the polygonCounts would be [4,4,4,4,4,4]
		totalPolygons = numPolygons * numVoxels
		polygonCounts = OpenMaya.MIntArray()
		#polygonConnects 
		#array of vertex connections for each polygon
		polygonConnects = OpenMaya.MIntArray()
		#set shared Normals for these vertices
		vertexNormals = OpenMaya.MVectorArray()
		#vertexColorArray
		vertexColorArray = OpenMaya.MColorArray()
		#vertexColorIndexArray
		vertexIndexArray = OpenMaya.MIntArray()
		#PolygonIDArray
		faceList = OpenMaya.MIntArray()
		#vertexWeightArray
		vertexWeightArray = OpenMaya.MDoubleArray()
		#vertexBlendWeightArray
		vertexBlendWeightArray = OpenMaya.MDoubleArray()

		for i in range (numVoxels):
			pVoxelCenterPosition = voxelCenterPosition[i]
			#Update VertexArray for VoxelMesh
			vertexList = [	OpenMaya.MFloatPoint(pVoxelCenterPosition.x-cubeHalfWidth, pVoxelCenterPosition.y-cubeHalfWidth, pVoxelCenterPosition.z-cubeHalfWidth), #vertex 0 
							OpenMaya.MFloatPoint(pVoxelCenterPosition.x-cubeHalfWidth, pVoxelCenterPosition.y-cubeHalfWidth, pVoxelCenterPosition.z+cubeHalfWidth), #vertex 1
							OpenMaya.MFloatPoint(pVoxelCenterPosition.x-cubeHalfWidth, pVoxelCenterPosition.y+cubeHalfWidth, pVoxelCenterPosition.z-cubeHalfWidth), #vertex 2
							OpenMaya.MFloatPoint(pVoxelCenterPosition.x-cubeHalfWidth, pVoxelCenterPosition.y+cubeHalfWidth, pVoxelCenterPosition.z+cubeHalfWidth), #vertex 3
							OpenMaya.MFloatPoint(pVoxelCenterPosition.x+cubeHalfWidth, pVoxelCenterPosition.y-cubeHalfWidth, pVoxelCenterPosition.z-cubeHalfWidth), #vertex 4
							OpenMaya.MFloatPoint(pVoxelCenterPosition.x+cubeHalfWidth, pVoxelCenterPosition.y-cubeHalfWidth, pVoxelCenterPosition.z+cubeHalfWidth), #vertex 5
							OpenMaya.MFloatPoint(pVoxelCenterPosition.x+cubeHalfWidth, pVoxelCenterPosition.y+cubeHalfWidth, pVoxelCenterPosition.z-cubeHalfWidth), #vertex 6
							OpenMaya.MFloatPoint(pVoxelCenterPosition.x+cubeHalfWidth, pVoxelCenterPosition.y+cubeHalfWidth, pVoxelCenterPosition.z+cubeHalfWidth), #vertex 7
						 ]

			for j in range (numVertices):
				vertexArray.append(vertexList[j])
				#here need to assign vertexWeight
				if self.skinCluster:
					for item in voxelWeights[i]:
						vertexWeightArray.append(item)
					vertexBlendWeightArray.append(voxelBlendWeights[i])
					#print [item for sublist in voxelWeights[i] for item in sublist]
				#here need to assign vertex color
				if texNodeName:
					vertexColor = cmds.colorAtPoint(texNodeName, o='RGB', u=uvArray[i][0], v=uvArray[i][1])
					mColor = OpenMaya.MColor(vertexColor[0],vertexColor[1],vertexColor[2])
					vertexColorArray.append(mColor)
					vertexIndexArray.append(i * numVertices + j)
				#print vertexColor

			#Update polygonCounts for VoxelMesh
			for j in range (numPolygons):
				polygonCounts.append(numVerticesPerPolygon)
				faceList.append(i*numPolygons+j)
			#Update polygonConnects for VoxelMesh
			#Update vertexNormals for VoxelMesh
			polygonConnectsList = [	0,1,3,2,
									1,5,7,3,
									4,6,7,5,
									2,6,4,0,
									0,4,5,1,
									2,3,7,6]

			vertexNormalsList = [	OpenMaya.MVector(-1.0,0.0,0.0),   		#vertex normal on face (0,1,3,2) #0
									OpenMaya.MVector(-1.0,0.0,0.0),			#vertex normal on face (0,1,3,2) #1
									OpenMaya.MVector(-1.0,0.0,0.0),			#vertex normal on face (0,1,3,2) #7
									OpenMaya.MVector(-1.0,0.0,0.0),			#vertex normal on face (0,1,3,2) #3

									OpenMaya.MVector(0.0,0.0,1.0),   		#vertex normal on face (1,5,7,3) #1
									OpenMaya.MVector(0.0,0.0,1.0),			#vertex normal on face (1,5,7,3) #5
									OpenMaya.MVector(0.0,0.0,1.0),			#vertex normal on face (1,5,7,3) #7 
									OpenMaya.MVector(0.0,0.0,1.0),			#vertex normal on face (1,5,7,3) #3

									OpenMaya.MVector(1.0,0.0,0.0),   		#vertex normal on face (4,6,7,5) #4
									OpenMaya.MVector(1.0,0.0,0.0),			#vertex normal on face (4,6,7,5) #6
									OpenMaya.MVector(1.0,0.0,0.0),			#vertex normal on face (4,6,7,5) #7
									OpenMaya.MVector(1.0,0.0,0.0),			#vertex normal on face (4,6,7,5) #5

									OpenMaya.MVector(0.0,0.0,-1.0),   		#vertex normal on face (2,6,4,0) #2
									OpenMaya.MVector(0.0,0.0,-1.0),			#vertex normal on face (2,6,4,0) #6
									OpenMaya.MVector(0.0,0.0,-1.0),			#vertex normal on face (2,6,4,0) #4
									OpenMaya.MVector(0.0,0.0,-1.0),			#vertex normal on face (2,6,4,0) #0

									OpenMaya.MVector(0.0,-1.0,0.0),   		#vertex normal on face (0,4,5,1) #0 
									OpenMaya.MVector(0.0,-1.0,0.0),			#vertex normal on face (0,4,5,1) #4
									OpenMaya.MVector(0.0,-1.0,0.0),			#vertex normal on face (0,4,5,1) #5
									OpenMaya.MVector(0.0,-1.0,0.0),			#vertex normal on face (0,4,5,1) #1

									OpenMaya.MVector(0.0,1.0,0.0),   		#vertex normal on face (2,3,7,6) #2
									OpenMaya.MVector(0.0,1.0,0.0),			#vertex normal on face (2,3,7,6) #3
									OpenMaya.MVector(0.0,1.0,0.0),			#vertex normal on face (2,3,7,6) #7
									OpenMaya.MVector(0.0,1.0,0.0)			#vertex normal on face (2,3,7,6) #6
								]			
			for j in range (numNormalsPerVoxel):
				vertexNormals.append(vertexNormalsList[j])
				polygonConnects.append(polygonConnectsList[j] + i * numVertices)

		mFnMesh = OpenMaya.MFnMesh()
		#shapeNode
		mMeshShape = mFnMesh.create (totalVertices, totalPolygons, vertexArray, polygonCounts, polygonConnects)
		mDagNode = OpenMaya.MFnDagNode(mMeshShape)
		mDagNode.setName('voxelGeom')
		#in case name existing:
		name = mDagNode.name()
		#print mDagNode.name()
		mDagPath = OpenMaya.MDagPath()
		mDagNode = OpenMaya.MFnDagNode(mDagNode.child(0))
		#print mDagNode.name()
		mDagNode.getPath(mDagPath)
		mCubeMesh = OpenMaya.MFnMesh(mDagPath)
		'''
		#assign Normal to the Cubes:

		#confused how to use setFaceVertexNormals
		#rewrite the function for setFaceVertexNormals based on setFaceVertexNormal
		#by query the facelist
		#support hard edge!

		for i in range (faceList.length()):
			for j in range (numVerticesPerPolygon):
				index = numVerticesPerPolygon * i + j
				mCubeMesh.setFaceVertexNormal(vertexNormals[index], i, polygonConnects[index])
		'''
		#'''
		#setVertexColor
		if texNodeName:
			mCubeMesh.createColorSetWithName('vertexColorSet')
			mCubeMesh.setIsColorClamped('vertexClorSet', True)
			mCubeMesh.setVertexColors(vertexColorArray, vertexIndexArray, None, OpenMaya.MFnMesh.kRGB)
		#'''
		 #create skincluster and remap weightData and blendWeight Data
		if self.skinCluster:
			influenceObj = cmds.skinCluster(q=True,inf=True)
			voxelSkinCluster = cmds.skinCluster(influenceObj, name, tsb=2, nw=2)
			mSelectionlist = OpenMaya.MSelectionList()
			mSelectionlist.add(voxelSkinCluster[0])
			mObj_voxelSkinCluster = OpenMaya.MObject()
			mSelectionlist.getDependNode(0,mObj_voxelSkinCluster)
			mfnSkinCluster = OpenMayaAnim.MFnSkinCluster(mObj_voxelSkinCluster)
			mDagPath,component = self.getSkinClusterData(mfnSkinCluster)
			influenceIndices = OpenMaya.MIntArray()
			for i in xrange(len(influenceObj)):
				influenceIndices.append(i)
			#print voxelWeights
			mfnSkinCluster.setWeights(mDagPath, component, influenceIndices,vertexWeightArray,False)
			mfnSkinCluster.setBlendWeights(mDagPath,component,vertexBlendWeightArray)

		#'''
		#--[retrive initialShadingGroup]--#
		mSelectionList = OpenMaya.MSelectionList()
		mSelectionList.add("initialShadingGroup")
		
		mObject_initShdGrp= OpenMaya.MObject()
		mSelectionList.getDependNode(0,mObject_initShdGrp) 
		mFnDependencyNode_initialShadingGroup = OpenMaya.MFnDependencyNode(mObject_initShdGrp)
		#mFnDependencyNode_initialShadingGroup.setObject(mObject_initShdGrp) 
		#name = mFnDependencyNode_initialShadingGroup.name() # Result: initialShadingGroup, so it ok so far
		fnSet = OpenMaya.MFnSet(mObject_initShdGrp)
		fnSet.addMember(mMeshShape)