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

My student work during the course:
Quick tutorial, easy way how you can transfer velocity vector from Houdini using Alembic.
Download : customVelocity.zip
Download : vtxNormalsToSoftHardEdges.zip
Usage:
import vtxNormalsToSoftHardEdges; vtxNormalsToSoftHardEdges.convertNormals();


My first Houdini Python Script. This script toggles Camera from PERSP view to SIDE view and back ( depends of camera vector ). You just need to make a Python shelf. Create new Python Tool and link my script.
Something like:
import view3d_toggle_views view3d_toggle_views.toggleViews()
Download : Toggle Views

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()
