Wednesday, July 29, 2015

Positon From Matrix

I am currently switching my stretchNode over to work on a matrix input rather than a vector input. I was having issues when querying the dataBlock of the MPxNode to return the matrix data. Pretty much I wasn't getting the correct information. The way this connection was made was the ".worldMatrix" attribute was connected to the '.inMatrix' attribute on my stretchNode. I accesed this with:

startMXDataH = block.inputValue(stretchNodeMX.aStartMX).asMatrix()

Now this was not playing nce with me. As I went further down the track I was not getting the correct information returned.

So here's what I have..I'll delve deeper tomorrow...

def compute(self,plug,block):
#method 1
#get matrix and translate from finding the dependency node and working from there
#returns the correct t.x,t.y and t.z
#-12.0540640814 5.6978884254 7.7806477623

sNode = self.thisMObject()
plugArray = OpenMaya.MPlugArray()
depNodeFn = OpenMaya.MFnDependencyNode(sNode)
startPlug = depNodeFn.findPlug(stretchNodeMX.aStartMX)
stObjMx = OpenMaya.MMatrix()
if plugArray.length()>0:
for i in range(0,plugArray.length()):
stObj = plugArray[i].node()
stDagNodeFn = OpenMaya.MFnDagNode(stObj)
stObjMx = stDagNodeFn.transformationMatrix()
stP = OpenMaya.MTransformationMatrix(stObjMx)
vec = stP.getTranslation(OpenMaya.MSpace.kWorld)
print vec.x,vec.y,vec.z

#method 2
#get the matrix data from the input plug and work from there
#returns the incorrrect t.x,t.y and t.z
#5.26354424712e-315 0.0 0.0078125

startMXDataH = block.inputValue(stretchNodeMX.aStartMX)
startMX = startMXDataH.asMatrix()
#just print the "translate" parts of the matrix - does not return what I'd expect.
print startMX(0,0),startMX(0,1),startMX(0,2)

#method 3
#returns the incorrrect t.x,t.y and t.z
#0.0 5.26354424712e-315 0.0

#get the transformation matrix to query the translation from there. Once again it returns the incorrect imformation
mxData = OpenMaya.MFnMatrixData()
stPTransformationMatrix = mxData.transformation()
stPTranslation = stPTransformationMatrix.getTranslation(OpenMaya.MSpace.kWorld)
print stPTranslation.x,stPTranslation.y,stPTranslation.z


Obviously something's going screwy with my coding here, and my use of the API. But anyways, it's all about digging through it and working out whats be continued tomorrow. Something's going wrong with either my creation of the matrix attribute and the kind of data there..but I'm pretty sure thats good. So it must be in the way I am querying the data from the dataBlock...hmmm.


No comments:

Post a Comment