Tell me please how can I get the angles ($rx, $ry, $rz) of the face to apply them to
polyProjection -ch 1 -type Planar -rx $rx -ry $ry -rz $rz $Face
Best plane projection is sometimes mistakenly.
Mel/Python/PyMel
Tell me please how can I get the angles ($rx, $ry, $rz) of the face to apply them to
polyProjection -ch 1 -type Planar -rx $rx -ry $ry -rz $rz $Face
Best plane projection is sometimes mistakenly.
Mel/Python/PyMel
I found the article with the definition of angles:
Find Euler rotation values of Maya matrix
Python API MTransformationMatrix.getRotation() bug
But I don’t know how to get a matrix of face. Who have any ideas?
Angles of the face?
The “angle” of the face is the face normal.
I did something like that in side a bigger script long ago. It calculated the average normal of the selected faces and applied a polyProjection in the opposite direction on them, basically…
[QUOTE=Wolfsong;7887]Angles of the face?
The “angle” of the face is the face normal.
I did something like that in side a bigger script long ago. It calculated the average normal of the selected faces and applied a polyProjection in the opposite direction on them, basically…[/QUOTE]
I would say about the Euler rotation.
Of course possible to check on the opposite face, but it’s better to solve the problem correctly than to fix an invalid path.
Can you find and show the script? It may be helpful
Review Inet and consider the available codes was born the following code:
import maya.cmds as cmds
import maya.OpenMaya as OpenMaya
import math
selList = OpenMaya.MSelectionList()
OpenMaya.MGlobal.getActiveSelectionList(selList)
selListIter = OpenMaya.MItSelectionList(selList)
while not selListIter.isDone():
dagPath = OpenMaya.MDagPath()
component = OpenMaya.MObject()
selListIter.getDagPath(dagPath, component)
myMesh=OpenMaya.MFnMesh(dagPath)
if component.apiType()==OpenMaya.MFn.kMeshPolygonComp onent:#Face
faceIter=OpenMaya.MItMeshPolygon( dagPath, component)
while not faceIter.isDone():
# ---------- get center point ----------#
centerP=faceIter.center(OpenMaya.MSpace.kWorld)
# ---------- get Normal ---------- #
normals=OpenMaya.MFloatVectorArray()
myMesh.getFaceVertexNormals(faceIter.index(),norma ls,OpenMaya.MSpace.kWorld)
total=OpenMaya.MFloatVector()
for i in range(normals.length()):
total += normals[i]
normal = total/normals.length()
# ---------- get Tangent ---------- #
tangents=OpenMaya.MFloatVectorArray()
myMesh.getFaceVertexTangents(faceIter.index(),tang ents,OpenMaya.MSpace.kWorld)
total=OpenMaya.MFloatVector()
for i in range(tangents.length()):
total += tangents[i]
tangent = total/tangents.length()
# ---------- get Binormal ---------- #
binormals=OpenMaya.MFloatVectorArray()
myMesh.getFaceVertexBinormals(faceIter.index(),bin ormals,OpenMaya.MSpace.kWorld)
total=OpenMaya.MFloatVector()
for i in range(binormals.length()):
total += binormals[i]
binormal = total/binormals.length()
# ---------- create Matrix ---------- #
matrix = OpenMaya.MMatrix()
OpenMaya.MScriptUtil.setDoubleArray(matrix[0], 0, tangent.x)
OpenMaya.MScriptUtil.setDoubleArray(matrix[0], 1, tangent.y)
OpenMaya.MScriptUtil.setDoubleArray(matrix[0], 2, tangent.z)
OpenMaya.MScriptUtil.setDoubleArray(matrix[0], 3, 0)
OpenMaya.MScriptUtil.setDoubleArray(matrix[1], 0, binormal.x)
OpenMaya.MScriptUtil.setDoubleArray(matrix[1], 1, binormal.y)
OpenMaya.MScriptUtil.setDoubleArray(matrix[1], 2, binormal.z)
OpenMaya.MScriptUtil.setDoubleArray(matrix[1], 3, 0)
OpenMaya.MScriptUtil.setDoubleArray(matrix[2], 0, normal.x)
OpenMaya.MScriptUtil.setDoubleArray(matrix[2], 1, normal.y)
OpenMaya.MScriptUtil.setDoubleArray(matrix[2], 2, normal.z)
OpenMaya.MScriptUtil.setDoubleArray(matrix[2], 3, 0)
OpenMaya.MScriptUtil.setDoubleArray(matrix[3], 0, centerP.x)
OpenMaya.MScriptUtil.setDoubleArray(matrix[3], 1, centerP.y)
OpenMaya.MScriptUtil.setDoubleArray(matrix[3], 2, centerP.z)
OpenMaya.MScriptUtil.setDoubleArray(matrix[3], 3, 0)
# First method! Get the rotation as a quaternion then convert to Euler as needed
#mTM = OpenMaya.MTransformationMatrix( matrix )
#eulers = mTM.rotation().asEulerRotation()
# Second method! Pull Euler rotation values from quaternion (MEulerRotation object)
quatRotate = OpenMaya.MQuaternion()
eulers = quatRotate.assign(matrix).asEulerRotation()
angles = [math.degrees(angle) for angle in (eulers.x, eulers.y, eulers.z)]
print angles
faceIter.next()
selListIter.next()
Confuses me the next block of code:
total=OpenMaya.MFloatVector()
for i in range(binormals.length()):
total += binormals[i]
binormal = total/binormals.length()
How to write a more compact form?