def numTofloatMMatrix(fm): floatM = om.MFloatMatrix() om.MScriptUtil.createFloatMatrixFromList([ fm[0], fm[1], fm[2], fm[3], fm[4], fm[5], fm[6], fm[7], fm[8], fm[9], fm[10], fm[11], fm[12], fm[13], fm[14], fm[15] ], floatM) return floatM
def sampleShadingNetworkAtPoints(nodeAttr, points): numSamples = len(points) pointArray = points pointArray = OpenMaya.MFloatPointArray() pointArray.setLength(numSamples) refPoints = OpenMaya.MFloatPointArray() refPoints.setLength(numSamples) for i, point in enumerate(points): location = OpenMaya.MFloatPoint(point[0], point[1], point[2]) pointArray.set(location, i) refPoints.set(location, i) # but we don't need these useShadowMap = False reuseMaps = False cameraMatrix = OpenMaya.MFloatMatrix() uCoords = None vCoords = None normals = None tangentUs = None tangentVs = None filterSizes = None # and the return arguments are empty.... resultColors = OpenMaya.MFloatVectorArray() resultTransparencies = OpenMaya.MFloatVectorArray() # sample the node network OpenMayaRender.MRenderUtil.sampleShadingNetwork( nodeAttr, numSamples, useShadowMap, reuseMaps, cameraMatrix, pointArray, uCoords, vCoords, normals, refPoints, tangentUs, tangentVs, filterSizes, resultColors, resultTransparencies) # return formatted sampled colours return resultColors
def compute(self, plug, data): if plug == self.outColor or plug.parent() == self.outColor: thisNode = self.thisMObject() fnThisNode = om.MFnDependencyNode(thisNode) uData = data.inputValue(self.inUCoord) uValue = uData.asFloat() uArray = om.MFloatArray(1) uArray.set(uValue, 0) timeData = data.inputValue(self.time) timeValue = timeData.asFloat() vData = data.inputValue(self.inVCoord) vValue = vData.asFloat() vArray = om.MFloatArray(1) vArray.set(vValue, 0) shadowsData = data.inputValue(self.useShadowMaps) shadowsValue = shadowsData.asBool() reShadowsData = data.inputValue(self.reUseShadowMaps) reShadowsValue = reShadowsData.asBool() filterSizeData = data.inputValue(self.filterSize) filterSizeValue = filterSizeData.asFloat() filterSizeArray = om.MFloatArray(1) filterSizeArray.set(filterSizeValue, 0) inPointData = data.inputValue(self.inPoint) inPointValue = inPointData.asFloatVector() inPointArray = om.MFloatPointArray(1) inPointArray.set(0, inPointValue.x, inPointValue.y, inPointValue.z, 1) useRefPointData = data.inputValue(self.useRefPoint) useRefPointValue = useRefPointData.asBool() refPointArray = om.MFloatPointArray(1) if useRefPointValue: refPointData = data.inputValue(self.refPoint) refPointValue = refPointData.asFloatVector() refPointArray.set(0, refPointValue.x, refPointValue.y, refPointValue.z, 1) else: refPointArray.set(0, inPointValue.x, inPointValue.y, inPointValue.z, 1) normalData = data.inputValue(self.normal) normalValue = normalData.asFloatVector() normalArray = om.MFloatVectorArray(1) normalArray.set(normalValue, 0) tangentUData = data.inputValue(self.tangentU) tangentUValue = tangentUData.asFloatVector() tangentUArray = om.MFloatVectorArray(1) tangentUArray.set(tangentUValue, 0) tangentVData = data.inputValue(self.tangentV) tangentVValue = tangentVData.asFloatVector() tangentVArray = om.MFloatVectorArray(1) tangentVArray.set(tangentVValue, 0) useSGData = data.inputValue(self.useSG) useSGValue = useSGData.asBool() plugArray = om.MPlugArray() inColorPlugName = "" inSGPlugName = "" sampleSource = "" isSGNode = False sgPlug = om.MPlug(thisNode, self.inSG) hasConnections = sgPlug.connectedTo(plugArray, 1, 0) if hasConnections: inSGPlugName = plugArray[0].name() inSGPlugNameSplit = inSGPlugName.split(".") sourceNode = om.MObject() sourceNode = plugArray[0].node() isSGNode = sourceNode.hasFn(om.MFn.kShadingEngine) inSGPlugName = inSGPlugNameSplit[0] else: inSGPlugName = "" colorPlug = om.MPlug(thisNode, self.inColor) hasConnections = colorPlug.connectedTo(plugArray, 1, 0) if hasConnections: inColorData = data.inputValue(self.inColor) inColorPlugName = plugArray[0].name() if useSGValue: if isSGNode: sampleSource = inSGPlugName elif inSGPlugName == "": print( "\"inSG\" has no connections. Please connect the \"message\" attribute of a shadingGroup to \"inSG\"" ) #return om.MStatus.kUnknownParameter else: print( inSGPlugName + " is not a shading group. Only the \"message\" attribute of a shadingGroup should be connected to \"inSG\"" ) #return om.MStatus.kUnknownParameter else: if not inColorPlugName == "": sampleSource = inColorPlugName else: print("\"inColor\" has no connections") #return om.MStatus.kUnknownParameter cameraMatData = data.inputValue(self.eyeToWorld) cameraMat = om.MFloatMatrix() cameraMat = cameraMatData.asFloatMatrix() resColors = om.MFloatVectorArray(1) resTransparencies = om.MFloatVectorArray(1) renderUtil = omRender.MRenderUtil renderUtil.sampleShadingNetwork( sampleSource, 1, shadowsValue, reShadowsValue, cameraMat, inPointArray, uArray, vArray, normalArray, refPointArray, tangentUArray, tangentVArray, filterSizeArray, resColors, resTransparencies) outColorRAttr = fnThisNode.attribute("outColorR") outColorRPlug = om.MPlug(thisNode, outColorRAttr) outColorRHandle = data.outputValue(outColorRPlug) outColorRHandle.setFloat(resColors[0].x) outColorRHandle.setClean() outColorGAttr = fnThisNode.attribute("outColorG") outColorGPlug = om.MPlug(thisNode, outColorGAttr) outColorGHandle = data.outputValue(outColorGPlug) outColorGHandle.setFloat(resColors[0].y) outColorGHandle.setClean() outColorBAttr = fnThisNode.attribute("outColorB") outColorBPlug = om.MPlug(thisNode, outColorBAttr) outColorBHandle = data.outputValue(outColorBPlug) outColorBHandle.setFloat(resColors[0].z) outColorBHandle.setClean() data.setClean(plug) #return om.MStatus.kSuccess else: print("something Failed")
def nodeInitializer(): nAttr = om.MFnNumericAttribute() tAttr = om.MFnTypedAttribute() mmAttr = om.MFnMatrixAttribute() mAttr = om.MFnMessageAttribute() uAttr = om.MFnUnitAttribute() plColorAtPoint.inColor = nAttr.createColor("inColor", "ic") nAttr.setKeyable(True) nAttr.setReadable(False) plColorAtPoint.useSG = nAttr.create("useSG", "sg", om.MFnNumericData.kBoolean, 0) nAttr.setReadable(False) nAttr.setChannelBox(True) plColorAtPoint.useShadowMaps = nAttr.create("useShadowMaps", "shd", om.MFnNumericData.kBoolean, 0) nAttr.setReadable(False) nAttr.setChannelBox(True) plColorAtPoint.reUseShadowMaps = nAttr.create("reUseShadowMaps", "rsh", om.MFnNumericData.kBoolean, 0) nAttr.setReadable(False) nAttr.setChannelBox(True) plColorAtPoint.inSG = mAttr.create("inShadingGroup", "isg") mAttr.setWritable(True) mAttr.setReadable(False) plColorAtPoint.inPoint = nAttr.createPoint("inPoint", "ip") nAttr.setKeyable(True) nAttr.setReadable(False) plColorAtPoint.useRefPoint = nAttr.create("useRefPoint", "urp", om.MFnNumericData.kBoolean, 0) nAttr.setReadable(False) nAttr.setChannelBox(True) plColorAtPoint.refPoint = nAttr.createPoint("refPoint", "rp") nAttr.setKeyable(True) nAttr.setReadable(False) plColorAtPoint.normal = nAttr.createPoint("normal", "n") nAttr.setKeyable(True) nAttr.setReadable(False) plColorAtPoint.tangentU = nAttr.createPoint("tangentU", "tu") nAttr.setKeyable(True) nAttr.setReadable(False) plColorAtPoint.tangentV = nAttr.createPoint("tangentV", "tv") nAttr.setKeyable(True) nAttr.setReadable(False) plColorAtPoint.filterSize = nAttr.create("filterSize", "fs", om.MFnNumericData.kFloat, 0.0) nAttr.setKeyable(True) nAttr.setReadable(False) plColorAtPoint.inUCoord = nAttr.create("inUCoord", "iuc", om.MFnNumericData.kFloat, 0.0) nAttr.setKeyable(True) nAttr.setReadable(False) plColorAtPoint.inVCoord = nAttr.create("inVCoord", "ivc", om.MFnNumericData.kFloat, 0.0) nAttr.setKeyable(True) nAttr.setReadable(False) defaultEyeToWorldMatrix = om.MFloatMatrix() defaultEyeToWorldMatrix.setToIdentity() plColorAtPoint.eyeToWorld = mmAttr.create("eyeToWorldMatrix", "etw", om.MFnNumericData.kFloat) mmAttr.setDefault(defaultEyeToWorldMatrix) mmAttr.setHidden(True) mmAttr.setReadable(False) mmAttr.setKeyable(True) plColorAtPoint.time = uAttr.create("time", "tm", om.MFnUnitAttribute.kTime, 0.0) uAttr.setHidden(False) uAttr.setReadable(False) uAttr.setKeyable(True) plColorAtPoint.outColor = nAttr.createColor("outColor", "oc") nAttr.setHidden(True) nAttr.setWritable(False) nAttr.setReadable(True) nAttr.setStorable(False) plColorAtPoint.addAttribute(plColorAtPoint.inColor) plColorAtPoint.addAttribute(plColorAtPoint.inUCoord) plColorAtPoint.addAttribute(plColorAtPoint.inVCoord) plColorAtPoint.addAttribute(plColorAtPoint.filterSize) plColorAtPoint.addAttribute(plColorAtPoint.useSG) plColorAtPoint.addAttribute(plColorAtPoint.useShadowMaps) plColorAtPoint.addAttribute(plColorAtPoint.reUseShadowMaps) plColorAtPoint.addAttribute(plColorAtPoint.inSG) plColorAtPoint.addAttribute(plColorAtPoint.inPoint) plColorAtPoint.addAttribute(plColorAtPoint.useRefPoint) plColorAtPoint.addAttribute(plColorAtPoint.refPoint) plColorAtPoint.addAttribute(plColorAtPoint.normal) plColorAtPoint.addAttribute(plColorAtPoint.tangentU) plColorAtPoint.addAttribute(plColorAtPoint.tangentV) plColorAtPoint.addAttribute(plColorAtPoint.eyeToWorld) plColorAtPoint.addAttribute(plColorAtPoint.time) plColorAtPoint.addAttribute(plColorAtPoint.outColor) plColorAtPoint.attributeAffects(plColorAtPoint.time, plColorAtPoint.outColor) plColorAtPoint.attributeAffects(plColorAtPoint.inColor, plColorAtPoint.outColor) plColorAtPoint.attributeAffects(plColorAtPoint.useSG, plColorAtPoint.outColor) plColorAtPoint.attributeAffects(plColorAtPoint.inSG, plColorAtPoint.outColor) plColorAtPoint.attributeAffects(plColorAtPoint.inPoint, plColorAtPoint.outColor) plColorAtPoint.attributeAffects(plColorAtPoint.useRefPoint, plColorAtPoint.outColor) plColorAtPoint.attributeAffects(plColorAtPoint.refPoint, plColorAtPoint.outColor) plColorAtPoint.attributeAffects(plColorAtPoint.normal, plColorAtPoint.outColor) plColorAtPoint.attributeAffects(plColorAtPoint.tangentU, plColorAtPoint.outColor) plColorAtPoint.attributeAffects(plColorAtPoint.tangentV, plColorAtPoint.outColor) plColorAtPoint.attributeAffects(plColorAtPoint.useShadowMaps, plColorAtPoint.outColor) plColorAtPoint.attributeAffects(plColorAtPoint.reUseShadowMaps, plColorAtPoint.outColor) plColorAtPoint.attributeAffects(plColorAtPoint.inUCoord, plColorAtPoint.outColor) plColorAtPoint.attributeAffects(plColorAtPoint.inVCoord, plColorAtPoint.outColor) plColorAtPoint.attributeAffects(plColorAtPoint.eyeToWorld, plColorAtPoint.outColor)
def compute(self, pPlug, pDataBlock): logger.debug('--Compute Method--') if pPlug != self.outputMatrixTransformAttribute: # Review: self. return None # data handles for each attribute and values inputCurveHandle = pDataBlock.inputValue(positionOnCurve.inputCurveAttribute) # get mDataHandle inputCurve = inputCurveHandle.asNurbsCurveTransformed() # mObject curvePositionHandle = pDataBlock.inputValue(positionOnCurve.curvePositionAttribute) # get mDataHandle curvePosition = curvePositionHandle.asDouble() # asDouble # rampScaleAttr, don't use dataBlock. MRampAttribute instead rampScaleHandle = OpenMaya.MRampAttribute(OpenMaya.MPlug(self.thisMObject(), positionOnCurve.rampScaleAttr)) rampTwistHandle = OpenMaya.MRampAttribute(OpenMaya.MPlug(self.thisMObject(), positionOnCurve.rampTwistAttr)) # convert data to C++ types # rampScaleValue util = OpenMaya.MScriptUtil() util.createFromDouble(0.0) valuePtr = util.asFloatPtr() rampScaleHandle.getValueAtPosition(curvePosition, valuePtr) # read value from memory rampScaleValue = util.getFloat(valuePtr) #TwistScaleValue util = OpenMaya.MScriptUtil() util.createFromDouble(0.0) valuePtr = util.asFloatPtr() rampTwistHandle.getValueAtPosition(curvePosition, valuePtr) # read value from memory rampTwistValue = util.getFloat(valuePtr) # outputHandle outputMatrixTransformHandle = pDataBlock.outputValue(positionOnCurve.outputMatrixTransformAttribute) # get mDataHandle # compute # create curves fn inputCurveMfn = OpenMaya.MFnNurbsCurve(inputCurve) curveLenght = inputCurveMfn.length() pointPosition = curvePosition * curveLenght curveParam = inputCurveMfn.findParamFromLength(pointPosition) # get Vectors curveNormal = inputCurveMfn.normal(max(curveParam - 0.001, 0.001)) curveTangent = inputCurveMfn.tangent(curveParam) curveBinormal = curveTangent ^ curveNormal # rampTwist rampTwistValue = (rampTwistValue - 0.5) * math.pi * 2 # possible add magnitude util = OpenMaya.MScriptUtil() util.createFromDouble(rampTwistValue) quaternion = OpenMaya.MQuaternion(rampTwistValue, curveTangent) curveNormal = curveNormal.rotateBy(quaternion) curveBinormal = curveBinormal.rotateBy(quaternion) # normalize vectors curveNormal.normalize() curveTangent.normalize() curveBinormal.normalize() # apply rampScale curveNormal *= rampScaleValue * 4 # possible rang attribute curveTangent *= rampScaleValue * 4 curveBinormal *= rampScaleValue * 4 curvePoint = OpenMaya.MPoint() inputCurveMfn.getPointAtParam(curveParam, curvePoint) # create transformMatrix mMatrix = OpenMaya.MFloatMatrix() OpenMaya.MScriptUtil.createFloatMatrixFromList((curveTangent.x, curveTangent.y, curveTangent.z, 0.0, curveNormal.x, curveNormal.y, curveNormal.z, 0.0, curveBinormal.x, curveBinormal.y, curveBinormal.z, 0.0, curvePoint.x, curvePoint.y, curvePoint.z, curvePoint.w), mMatrix) # set output Value outputMatrixTransformHandle.setMFloatMatrix(mMatrix) # Mark output as clean pDataBlock.setClean(pPlug)
def sampleColorAtParticle(textureNode, particleShapeNode): # get the particle object as an MObject selectionList = om.MSelectionList() selectionList.add(particleShapeNode) particleObject = om.MObject() selectionList.getDependNode(0, particleObject) # create a MFnParticle to get to the data particleDataFn = omFX.MFnParticleSystem(particleObject) # get the positionPP data posPPArray = om.MVectorArray() particleDataFn.getPerParticleAttribute("position", posPPArray) # these are the arguments required to sample a 3d texture: shadingNodeName = textureNode numSamples = posPPArray.length() pointArray = om.MFloatPointArray() pointArray.setLength(numSamples) refPoints = om.MFloatPointArray() refPoints.setLength(numSamples) for i in range(posPPArray.length()): particlePosVector = om.MVector() particlePosVector = posPPArray[i] location = om.MFloatPoint( particlePosVector[0], particlePosVector[1], particlePosVector[2]) pointArray.set(location, i) refPoints.set(location, i) # but we don't need these useShadowMap = False reuseMaps = False cameraMatrix = om.MFloatMatrix() uCoords = None vCoords = None normals = None tangentUs = None tangentVs = None filterSizes = None # and the return arguments are empty.... resultColors = om.MFloatVectorArray() resultTransparencies = om.MFloatVectorArray() # this is the command wot samples omr.MRenderUtil.sampleShadingNetwork(shadingNodeName, numSamples, useShadowMap, reuseMaps, cameraMatrix, pointArray, uCoords, vCoords, normals, refPoints, tangentUs, tangentVs, filterSizes, resultColors, resultTransparencies) # use the sampled colours to set rgbPP resultPPColors = om.MVectorArray() resultPPColors.clear() for i in range(resultColors.length()): floatVector = om.MFloatVector(resultColors[i]) vector = om.MVector(floatVector) resultPPColors.append(vector) particleDataFn.setPerParticleAttribute("rgbPP", resultPPColors)
# coding:utf-8 # MMatrix api from maya import OpenMaya as om mat = om.MMatrix() mat.setToIdentity() def printMatrix(mat): for i in range(4): row = '' for j in range(4): value = mat(i, j) row += '%s, ' % value print(row) fm = om.MFloatMatrix() fm.get(mat.matrix) dm = om.MMatrix() dm.get(fm.matrix) inv = dm.inverse() type(inv) # Result: <class 'maya.OpenMaya.MMatrix'> # printMatrix(inv) trans = dm.transpose() printMatrix(trans)
def sample_shading_node(shading_node, point_data, filter_size=0): """ sample the given shading node for each point in the given point data object :return """ # view = om.M3dView().active3dView() # cam_dag = om.MDagPath() # view.getCamera(cam_dag) # dag_fn = om.MFnDagNode(cam_dag) # matrix_plug = dag_fn.findPlug('worldMatrix') # create temp material and shading engine for sampling old_selection = cmds.ls(sl=True, l=True) shd = cmds.shadingNode('surfaceShader', name='shaderEvalTemp', asShader=True) shd_grp = cmds.sets(name='%sSG' % shd, empty=True, renderable=True, noSurfaceShader=True) cmds.connectAttr('%s.outColor' % shd, '%s.surfaceShader' % shd_grp) cmds.connectAttr(shading_node + '.outColor', shd + '.outColor') points = om.MFloatPointArray() # ref_points = om.MFloatPointArray() normals = om.MFloatVectorArray() # u_tangent = om.MFloatVectorArray() # get binormals to sample dependend shaders # v_tangent = om.MFloatVectorArray() u_coords = om.MFloatArray() v_coords = om.MFloatArray() filter_size_array = om.MFloatArray() cam_matrix = om.MFloatMatrix() # get camera matrix to sample view dependend shader for i, (position, normal, poly_id, u_coord, v_coord) in enumerate(point_data): points.append(om.MFloatPoint(position[0], position[1], position[2])) normals.append(om.MFloatVector(normal[0], normal[1], normal[2])) u_coords.append(u_coord) v_coords.append(v_coord) # u_tangent.append(om.MFloatVector(0,1,0)) # v_tangent.append(om.MFloatVector(1,0,0)) filter_size_array.append(filter_size) color = om.MFloatVectorArray() alpha = om.MFloatVectorArray() omr.MRenderUtil.sampleShadingNetwork(shd_grp, len(point_data), False, False, cam_matrix, points, u_coords, v_coords, normals, points, None, None, None, color, alpha) color_result = [(color[i].x, color[i].y, color[i].z) for i in xrange(color.length())] alpha_result = [(alpha[i].x, alpha[i].y, alpha[i].z) for i in xrange(alpha.length())] cmds.delete((shd, shd_grp)) cmds.select(old_selection) return color_result, alpha_result
def compute(self, pPlug, pDataBlock): # node behavior # check outputs if pPlug == elevatorNode.outputMatrixTransformAttribute: logger.debug('__COMPUTE__') # get Data handles # num Floors numFloorHandle = pDataBlock.inputValue(elevatorNode.numFloorAttribute) numFloor = numFloorHandle.asInt() # stick length lengthStickHandle = pDataBlock.inputValue(elevatorNode.lengthStickAttribute) lengthStick = lengthStickHandle.asDouble() # stick distance distanceStickHandle = pDataBlock.inputValue(elevatorNode.distanceStickAttribute) distanceStick = distanceStickHandle.asDouble() # inputMatrixTransforms inputMatrix01Handle = pDataBlock.inputValue(elevatorNode.inputMatrix01Attribute) inputMatrix01Attribute = inputMatrix01Handle.asFloatMatrix() inputMatrix02Handle = pDataBlock.inputValue(elevatorNode.inputMatrix02Attribute) inputMatrix02Attribute = inputMatrix02Handle.asFloatMatrix() # set ouputTransformMatrix # get output outputMatrixTransformHandle = pDataBlock.outputArrayValue(elevatorNode.outputMatrixTransformAttribute) # get base Z vector from transform Matrix baseVectorZ = OpenMaya.MVector(inputMatrix01Attribute(2,0), inputMatrix01Attribute(2,1), inputMatrix01Attribute(2,2)) baseVectorZ.normalize() # get distance vector, position im01 - im02 # Explanation: this way we don't need mscriptUtils distanceVector = OpenMaya.MVector(inputMatrix02Attribute(3, 0) - inputMatrix01Attribute(3, 0), inputMatrix02Attribute(3, 1) - inputMatrix01Attribute(3, 1), inputMatrix02Attribute(3, 2) - inputMatrix01Attribute(3, 2)) floorVector = distanceVector / numFloor if floorVector.length() > lengthStick: return OpenMaya.kUnknownParameter # calculate angle, length of stick object must touch the upper floor # we can use pitagoras theorem # floorVector -> C # ? = -> c # lengthStick -> H: H^2 = c^2 + C^2 ::::> H^2 - C^2 = c^2 baseLength = (lengthStick**2 - (floorVector.length())**2)**0.5 # cosinus => H / c cosinus = baseLength / lengthStick angle = math.acos(cosinus) # radians # calculate vectors xVector = OpenMaya.MVector(inputMatrix01Attribute(0,0), inputMatrix01Attribute(0,1), inputMatrix01Attribute(0,2)) zVector = xVector ^ floorVector xVector = floorVector ^ zVector # todo: maybe recalculate cross product X # rotateVectors base, zVector same quaternionLower = OpenMaya.MQuaternion(angle, zVector) xVectorLower = xVector.rotateBy(quaternionLower) yVectorLower = OpenMaya.MVector(floorVector).rotateBy(quaternionLower) # rotateVectorsUpper quaternionUpper = OpenMaya.MQuaternion(-angle, zVector) xVectorUpper = xVector.rotateBy(quaternionUpper) yVectorUpper = OpenMaya.MVector(floorVector).rotateBy(quaternionUpper) # Normalize lengths xVectorLower.normalize() yVectorLower.normalize() zVector.normalize() xVectorUpper.normalize() yVectorUpper.normalize() for i in range(numFloor): # 4 sticks by floor logger.debug('Per floor value: %s,%s,%s' % ( floorVector.x * (i + 1), floorVector.y * (i + 1), floorVector.z * (i + 1))) for n in range(4): util = OpenMaya.MScriptUtil() mFloatMatrix = OpenMaya.MFloatMatrix() if n == 0: util.createFloatMatrixFromList([xVectorLower.x, xVectorLower.y, xVectorLower.z, 0, yVectorLower.x, yVectorLower.y, yVectorLower.z, 0, zVector.x, zVector.y, zVector.z, 0, floorVector.x * i + inputMatrix01Attribute(3, 0)+baseVectorZ.x * distanceStick, floorVector.y * i + inputMatrix01Attribute(3, 1)+baseVectorZ.y * distanceStick, floorVector.z * i + inputMatrix01Attribute(3, 2)+baseVectorZ.z * distanceStick, 1], mFloatMatrix) elif n == 1: util.createFloatMatrixFromList([xVectorUpper.x, xVectorUpper.y, xVectorUpper.z, 0, yVectorUpper.x, yVectorUpper.y, yVectorUpper.z, 0, zVector.x, zVector.y, zVector.z, 0, floorVector.x * (i+1) + inputMatrix01Attribute(3, 0)+baseVectorZ.x * distanceStick, floorVector.y * (i+1) + inputMatrix01Attribute(3, 1)+baseVectorZ.y * distanceStick, floorVector.z * (i+1) + inputMatrix01Attribute(3, 2)+baseVectorZ.z * distanceStick, 1], mFloatMatrix) elif n == 2: util.createFloatMatrixFromList([xVectorLower.x, xVectorLower.y, xVectorLower.z, 0, yVectorLower.x, yVectorLower.y, yVectorLower.z, 0, zVector.x, zVector.y, zVector.z, 0, floorVector.x * i + inputMatrix01Attribute(3, 0)-baseVectorZ.x * distanceStick, floorVector.y * i + inputMatrix01Attribute(3, 1)-baseVectorZ.y * distanceStick, floorVector.z * i + inputMatrix01Attribute(3, 2)-baseVectorZ.z * distanceStick, 1], mFloatMatrix) elif n == 3: util.createFloatMatrixFromList([xVectorUpper.x, xVectorUpper.y, xVectorUpper.z, 0, yVectorUpper.x, yVectorUpper.y, yVectorUpper.z, 0, zVector.x, zVector.y, zVector.z, 0, floorVector.x * (i + 1) + inputMatrix01Attribute(3, 0)-baseVectorZ.x * distanceStick, floorVector.y * (i + 1) + inputMatrix01Attribute(3, 1)-baseVectorZ.y * distanceStick, floorVector.z * (i + 1) + inputMatrix01Attribute(3, 2)-baseVectorZ.z * distanceStick, 1], mFloatMatrix) try: outputMatrixTransformHandle.jumpToArrayElement(i*4 + n) # attr output index *4 outputIndexHandle = outputMatrixTransformHandle.outputValue() # set output outputIndexHandle.setMFloatMatrix(mFloatMatrix) outputIndexHandle.setClean() except: return OpenMaya.kUnknownParameter logger.debug('__End COMPUTE__') outputMatrixTransformHandle.setAllClean() outputMatrixTransformHandle.setClean() pDataBlock.setClean(pPlug) else: sys.stderr.write('Failed trying to compute locator. stack trace: \n') sys.stderr.write(traceback.format_exc()) return OpenMaya.kUnknownParameter return True