Is it possible to output direction vector in MPxLocator node using MFnNumericAttribute ??

*Draw arrow shape openGL polygon using MPxLocatorNode::draw() method
*output direction vector
Quote 0 0
x = nAttr.create("x","x",MFnNumericData::kDouble);
y = nAttr.create("y","y",MFnNumericData::kDouble);
z = nAttr.create("z","z",MFnNumericData::kDouble);
dir = nAttr.create("direction", d", x,y,z);
Quote 0 0
Below code is For creating arrow shape using MFnmesh, now i want to insert this in MPxLocator & output direction between vertex 13 & 12. And one more question why normal of resultant mesh is set to face ??

import maya.OpenMaya as om
import maya.cmds as mc
import maya.mel as mm

locPos = [[-0.05000000074505806, 0.0, 0.05000000074505806], [0.05000000074505806, 0.0, 0.05000000074505806], [0.05000000074505806, 1.0, 0.05000000074505806], [-0.05000000074505806, 1.0, 0.05000000074505806], [0.05000000074505806, 0.0, -0.05000000074505806], [-0.05000000074505806, 0.0, -0.05000000074505806], [0.05000000074505806, 1.0, -0.05000000074505806], [-0.05000000074505806, 1.0, -0.05000000074505806], [-0.125, 1.0, -0.125], [-0.125, 1.0, 0.125], [0.125, 1.0, 0.125], [0.125, 1.0, -0.125], [-0.0014583021402359009, 1.5859489440917969, -0.0014583021402359009], [0.0, 0.0, 0.0]]
#Create Single Face
#Get Vert as MPoint from loc position
vertices = []
for locP in locPos:
  vertices.append(om.MFloatPoint(locP[0], locP[1], locP[2]))
#Create MFnmesh and its addPolygon command with a MPoint array for the face
meshFn = om.MFnMesh()
pointTolerance = 0.001
faceArray = om.MFloatPointArray() 
#setting array with the vert and its index
#All at once
numVertices = 14
numPolygons = 16
vertexFloatPointArray = om.MFloatPointArray()
for vertex in vertices:
count = [4,4,4,4,4,4,4,4,3,3,3,3,3,3,3,3]
polyCount = om.MIntArray()
for c in count:
connections = [0,1,2,3,1,4,6,2,4,5,7,6,5,0,3,7,3,2,10,9,2,6,11,10,6,7,8,11,7,3,9,8,9,10,12,10,11,12,11,8,12,8,9,12,0,13,1,1,13,4,4,13,5,5,13,0]
#note, making all the connection counter clockwise, to get normal pointing outwards
polyConnection = om.MIntArray()
for connection in connections:
meshFn.create(numVertices, numPolygons, vertexFloatPointArray, polyCount, polyConnection)

Quote 0 0
Your words "to output the direction between vertex 12 and 13" can mean many things. Can you specify ?

Find an example of a python scripted node in the devkit - there should be some.
If not, you can find one online - there should be plenty.
You can start with pyExpression, but it may be too confusing, because there is a lot of code.
Then the easiest way to draw something is to plop your code in the ::draw method for VP1 or in the yourNodeDrawOverride:draw method for VP2.

Why normals are set to face ?
That's the standard behavior.

Looking at your code - there are quite few things that are not right.
I would not say they are wrong, but not right for sure. :)

1. Try to use PythonApi 2 in general. Especially true for new code.
2. Do not use Python containers to store array data, they are slow.
3. Do not append to arrays if you know the number of elements.
4. No reason to use the ::set operator if you can just use the = one.
5. I understand this is a study, so i just state the obvious - stay away from python scripted nodes in production, especially for drawing on screen. Performance will be gone in no time from your Maya session.

Hope this can get you on the right track.
Quote 0 0