PDA

View Full Version : Angles Face for polyProjection


TITANius
10-20-2010, 11:29 AM
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

jaydru
10-20-2010, 03:54 PM
are you talking about the normal direction if so...

//your face[/QUOTE]
string $face = "pCube1.f[1]";

//local face normal
string $infoStr[] = `polyInfo -faceNormals $face`;
string $tokens[];
int $numTokens = `tokenize $infoStr[0] $tokens`;
float $fNorm[];

$fNorm[0] = $tokens[2];
$fNorm[1] = $tokens[3];
$fNorm[2] = $tokens[4];

//now get the that normal in world space
float $worldMatrix[16] = `xform -q -ws -matrix $face`;
$fNorm = `pointMatrixMult $fNorm $worldMatrix`;

print $fNorm;

james

TITANius
10-20-2010, 06:41 PM
are you talking about the normal direction if so...

//your face
string $face = "pCube1.f[1]";

//local face normal
string $infoStr[] = `polyInfo -faceNormals $face`;
string $tokens[];
int $numTokens = `tokenize $infoStr[0] $tokens`;
float $fNorm[];

$fNorm[0] = $tokens[2];
$fNorm[1] = $tokens[3];
$fNorm[2] = $tokens[4];

//now get the that normal in world space
float $worldMatrix[16] = `xform -q -ws -matrix $face`;
$fNorm = `pointMatrixMult $fNorm $worldMatrix`;

print $fNorm;

Yes, this code we get the normal vector, but need angles in each of the projections for apply them to
polyProjection, which accepts only the angles.

In other words, as the normal vector to translate into the angles of the projections?

TITANius
10-20-2010, 09:50 PM
I found the article with the definition of angles:
Find Euler rotation values of Maya matrix (http://www.akeric.com/blog/?p=1067)
Python API MTransformationMatrix.getRotation() bug (http://www.rtrowbridge.com/blog/2009/02/python-api-mtransformationmatrixgetrotation-bug/)

But I don't know how to get a matrix of vectors face. Who have any ideas? :)

TITANius
10-22-2010, 11:30 AM
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.kMeshPolygonComponent:#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(),normals,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(),tangents,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(),binormals,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?

CGTalk Moderation
10-22-2010, 11:30 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.