OpenMaya.MTransformationMatrix Rotation matrix from 3 vectors
Small practical example with Maya API python functionalities
Generate Rotation matrix using 3 vectors (normal, tangent, up)
Download Source Code
Small practical example with Maya API python functionalities
Generate Rotation matrix using 3 vectors (normal, tangent, up)
Download Source Code
import maya.OpenMaya as OpenMaya def main(): m_color = ( 0.0, 1.0, 0.0, 1.0 ) m_color = float4Torgba(m_color) generateTexture("c:/tmp","color01",m_color) def generateTexture(m_path,m_fileName,m_color): try: m_util = OpenMaya.MScriptUtil #------------- m_height = 16 m_width = 16 m_depth = 4 #------------- m_image = OpenMaya.MImage() m_image.create(m_height, m_width, m_depth ) m_pixels = m_image.pixels() #------------- m_arrayLen = m_width * m_height * m_depth for i in range(0, m_arrayLen, m_depth): m_util.setUcharArray(m_pixels, i+0, m_color[0]) m_util.setUcharArray(m_pixels, i+1, m_color[1]) m_util.setUcharArray(m_pixels, i+2, m_color[2]) m_util.setUcharArray(m_pixels, i+3, 0) m_image.setPixels(m_pixels, m_height, m_width) m_image.writeToFile( "{}/{}.png".format(m_path,m_fileName), '.png' ) except: OpenMaya.MGlobal.displayWarning("Can't save file to {}/{}.png".format(m_path,m_fileName)) return False else: return True def float4Torgba((m_r,m_g,m_b,m_a)): m_red = int(m_r * 255.0) m_green = int(m_g * 255.0) m_blue = int(m_b * 255.0) m_alpha = int(m_a * 255.0) return (m_red, m_green, m_blue, m_alpha) main()
The same like in 3dsmax. Attach polygons via Maya Python Api and Maya cmds to existing mesh.
Not combine, no cheating. Also with skinning support.
Limitation : very slow.
Download : attachObjects.zip
import sys import maya.cmds as cmds path = 'C:/maya_scripts/modeling' if path not in sys.path: sys.path.append(path) import attachObjects; attachObjects.main();
Quick example working with OpenMaya.MFnMesh setUV and assignUV.
Limitation : works only on objects with no construction history.
Download : apiGenerateUV.zip
Download : vtxNormalsToSoftHardEdges.zip
Usage:
import vtxNormalsToSoftHardEdges; vtxNormalsToSoftHardEdges.convertNormals();
Quick example
import maya.OpenMaya as OpenMaya m_obj = OpenMaya.MObject() # should get from any code above m_dagPath = OpenMaya.MDagPath() if m_obj.hasFn( OpenMaya.MFn.kDagNode ): OpenMaya.MDagPath.getAPathTo( m_obj, m_dagPath ) print( m_dagPath.fullPathName() )
Quick example
import maya.OpenMaya as OpenMaya m_iterator = OpenMaya.MItDag( OpenMaya.MItDag.kDepthFirst ) while not m_iterator.isDone(): m_obj = m_iterator.currentItem() m_objFn = OpenMaya.MFnDagNode( m_obj ) #if ( OpenMaya.MFn.kMesh == m_obj.apiType() ): print( m_objFn.fullPathName() ) m_iterator.next()
Select the node and run:
m_list = getAllExtraAttributes() print( m_list )
import maya.OpenMaya as OpenMaya m_iterator = OpenMaya.MItDependencyNodes( OpenMaya.MFn.kFileTexture ) m_nodeFn = OpenMaya.MFnDependencyNode() while not m_iterator.isDone(): m_object = m_iterator.thisNode() m_nodeFn.setObject( m_object ) print( " --- {0} --- ".format( m_nodeFn.name()) ) for i in range( m_nodeFn.attributeCount() ): m_atrr = m_nodeFn.attribute(i) m_fnAttr = OpenMaya.MFnAttribute( m_atrr ) print( m_fnAttr.name() ) m_iterator.next()
Dealt Maya API. Here I decided to post some example functions. The basic idea was using Maya API Python classes realize workflow with extra attributes at native Maya node. Suppose you want to make a script that stores some data in one native Maya node (in the script node, for example), and if user do not have your script, nothing terrible will happen, node modified by you will work without any troubles. Sorry for my English.
You should get something like this: