Yes. You are assuming to know what mesh shape does internally when it reads the data from the inMesh plug. It might very well be that it gets the mesh points and then transfroms them by the MDataHandle::geometryTransformMatrix() to get the local coordinates.
Another test you can make is constrain a locator to the moved cube in your example using the Point on Poly Constraint. Note that it uses the worldMesh[0] as input to target, now replace the connection with outMesh instead and observe the difference. Cheers! On Sat, Jan 5, 2019 at 11:52 AM Marcus Ottosson <konstrukt...@gmail.com> wrote: > wordMesh returns a mesh with vertex coordinates in world coordinates, > taking the movement of mesh shape parent transform node (per instance) into > account > > But does it really? > > That seems the logical conclusion, but I’ve never seen that actually be > the case. > > Here’s an example. > > from maya import cmds > > transform, generator = cmds.polyCube() > shape = cmds.listRelatives(transform, shapes=True)[0] > > clone = cmds.createNode("transform", name="Clone") > mesh = cmds.createNode("mesh", parent=clone) > > cmds.connectAttr(shape + ".worldMesh[0]", mesh + ".inMesh") > cmds.move(0, 2, 0, transform) > > Apparently, the “clone” (wireframe) isn’t getting the worldspace positions > of those vertices. > > [image: image.png] > > On Sat, 5 Jan 2019 at 15:55, Serguei Kalentchouk < > serguei.kalentch...@gmail.com> wrote: > >> Glad to hear that it's working now! >> >> outMesh returns a mesh with vertex coordinates in local space, as if the >> mesh never moves from the world origin. >> wordMesh returns a mesh with vertex coordinates in world coordinates, >> taking the movement of mesh shape parent transform node (per instance) into >> account. >> >> Hope that helps understand it. >> >> >> On Fri, Jan 4, 2019 at 10:33 PM 徐一雄 <xuyixiong...@gmail.com> wrote: >> >>> Hello Sir, >>> I used to connect the '*Out Mesh*' to the inMesh. >>> Just as you said, I change it to *worldMesh[0]*, and it works !!! But I >>> don't know why... >>> Can you tell me the difference between worldMesh and Out Mesh? >>> Thank you very much >>> Yixiong Xu >>> 2019.01.05 >>> >>> 在 2019年1月4日星期五 UTC+8下午11:55:03,serguei.k...@gmail.com写道: >>>> >>>> Hi Yixiong, >>>> Are you connecting worldMesh[0] as input for inMesh? >>>> >>>> On Thu, Jan 3, 2019 at 11:46 PM 徐一雄 <xuyixi...@gmail.com> wrote: >>>> >>>>> Hello everyone, i'm a newbee to maya python API. >>>>> Recently, I'm struggle in the single ray tracer. >>>>> I build a custom MPxNode to compute the hitPoint when the ray hit the >>>>> sphere. >>>>> The ray is build by 2 locators in space. >>>>> If the sphere is at the origin point of the world space, everything >>>>> seems OK. >>>>> But here is the* problem*: >>>>> When I transform the sphere object, e.x translate a little distance. >>>>> The hitPoint should translate on the sphere but now it doesn't . >>>>> I know that when I transform the sphere, the input values of the >>>>> custom node have't change and compute function doesn't be called. >>>>> I have tried that to add a transform attribute to call the compute >>>>> function but it doesn't work. I think the hitPoint should be calculate by >>>>> multiply a matrix. >>>>> So how can I achieve that when I transform the sphere, the hit point >>>>> on the sphere also change by the direction of the ray. >>>>> Thank you very much. >>>>> >>>>> Here is the *code*: >>>>> >>>>> import maya.OpenMaya as om >>>>> import maya.OpenMayaMPx as ompx >>>>> >>>>> nodeName = 'RayTracer' >>>>> nodeID = om.MTypeId(0X100fff) >>>>> >>>>> >>>>> class MeshIntersectionNode(ompx.MPxNode): >>>>> # Class Attrs >>>>> # INPUT >>>>> Loc_1_Pos = om.MObject() >>>>> Loc_2_Pos = om.MObject() >>>>> >>>>> inMesh = om.MObject() >>>>> >>>>> # OUTPUT >>>>> Loc_3_Pos = om.MObject() >>>>> >>>>> def __init__(self): >>>>> ompx.MPxNode.__init__(self) >>>>> >>>>> def compute(self, plug, dataBlock): >>>>> if plug != MeshIntersectionNode.Loc_3_Pos: >>>>> return om.kUnknownParameter >>>>> >>>>> locator1Vector = >>>>> om.MVector(dataBlock.inputValue(MeshIntersectionNode.Loc_1_Pos).asFloatVector()) >>>>> locator2Vector = >>>>> om.MVector(dataBlock.inputValue(MeshIntersectionNode.Loc_2_Pos).asFloatVector()) >>>>> inputMeshObj = >>>>> dataBlock.inputValue(MeshIntersectionNode.inMesh).asMesh() >>>>> >>>>> direction = om.MFloatVector(locator2Vector - locator1Vector) >>>>> >>>>> sourcePoint = >>>>> om.MFloatPoint(dataBlock.inputValue(MeshIntersectionNode.Loc_1_Pos).asFloatVector()) >>>>> >>>>> inputMeshMFn = om.MFnMesh(inputMeshObj) >>>>> >>>>> hitPoints = om.MFloatPoint() >>>>> >>>>> tolerance = float(0.0) >>>>> >>>>> inputMeshMFn.closestIntersection(sourcePoint, direction, None, >>>>> None, False, om.MSpace.kWorld, >>>>> 10000.0, False, None, >>>>> hitPoints, None, None, None, None, None, tolerance) >>>>> >>>>> outputPoint = >>>>> dataBlock.outputValue(MeshIntersectionNode.Loc_3_Pos) >>>>> >>>>> if hitPoints[0]: >>>>> outputVector = om.MFloatVector(hitPoints.x, hitPoints.y, >>>>> hitPoints.z) >>>>> else: >>>>> outputVector = om.MFloatVector(0.0, 0.0, 0.0) >>>>> >>>>> outputPoint.setMFloatVector(outputVector) >>>>> >>>>> dataBlock.setClean(plug) >>>>> >>>>> >>>>> def nodeCreator(): >>>>> return ompx.asMPxPtr(MeshIntersectionNode()) >>>>> >>>>> >>>>> def nodeInitializer(): >>>>> MFnNumericAttr = om.MFnNumericAttribute() >>>>> MFnMeshAttribute = om.MFnTypedAttribute() >>>>> >>>>> # create attribute >>>>> # input >>>>> MeshIntersectionNode.Loc_1_Pos = >>>>> MFnNumericAttr.createPoint('Locator1Position', 'Loc1Pos') >>>>> MFnNumericAttr.setWritable(1) >>>>> MFnNumericAttr.setKeyable(1) >>>>> MeshIntersectionNode.addAttribute(MeshIntersectionNode.Loc_1_Pos) >>>>> >>>>> MeshIntersectionNode.Loc_2_Pos = >>>>> MFnNumericAttr.createPoint('Locator2Position', 'Loc2Pos') >>>>> MFnNumericAttr.setWritable(1) >>>>> MFnNumericAttr.setKeyable(1) >>>>> MeshIntersectionNode.addAttribute(MeshIntersectionNode.Loc_2_Pos) >>>>> >>>>> MeshIntersectionNode.inMesh = MFnMeshAttribute.create('inMesh', 'im', >>>>> om.MFnData.kMesh) >>>>> MFnMeshAttribute.setWritable(1) >>>>> MFnMeshAttribute.setKeyable(1) >>>>> MeshIntersectionNode.addAttribute(MeshIntersectionNode.inMesh) >>>>> >>>>> # output >>>>> MeshIntersectionNode.Loc_3_Pos = >>>>> MFnNumericAttr.createPoint('Locator3Position', 'Loc3Pos') >>>>> MFnNumericAttr.setWritable(0) >>>>> MFnNumericAttr.setReadable(1) >>>>> MeshIntersectionNode.addAttribute(MeshIntersectionNode.Loc_3_Pos) >>>>> >>>>> # make influence >>>>> MeshIntersectionNode.attributeAffects(MeshIntersectionNode.Loc_1_Pos, >>>>> MeshIntersectionNode.Loc_3_Pos) >>>>> MeshIntersectionNode.attributeAffects(MeshIntersectionNode.Loc_2_Pos, >>>>> MeshIntersectionNode.Loc_3_Pos) >>>>> MeshIntersectionNode.attributeAffects(MeshIntersectionNode.inMesh, >>>>> MeshIntersectionNode.Loc_3_Pos) >>>>> >>>>> >>>>> def initializePlugin(mObj): >>>>> mPlugin = ompx.MFnPlugin(mObj, 'Yixiong Xu', '1.0') >>>>> >>>>> try: >>>>> mPlugin.registerNode(nodeName, nodeID, nodeCreator, >>>>> nodeInitializer) >>>>> except: >>>>> raise RuntimeError >>>>> print 'Failed to register node.' >>>>> >>>>> >>>>> def uninitializePlugin(mObj): >>>>> mPlugin = ompx.MFnPlugin(mObj) >>>>> >>>>> try: >>>>> mPlugin.deregisterNode(nodeID) >>>>> except: >>>>> raise RuntimeError >>>>> print 'Failed to deregister node.' >>>>> >>>>> -- >>>>> You received this message because you are subscribed to the Google >>>>> Groups "Python Programming for Autodesk Maya" group. >>>>> To unsubscribe from this group and stop receiving emails from it, send >>>>> an email to python_inside_maya+unsubscr...@googlegroups.com. >>>>> To view this discussion on the web visit >>>>> https://groups.google.com/d/msgid/python_inside_maya/9002b2ca-1d44-43d7-9f76-b8dcce2455f6%40googlegroups.com >>>>> <https://groups.google.com/d/msgid/python_inside_maya/9002b2ca-1d44-43d7-9f76-b8dcce2455f6%40googlegroups.com?utm_medium=email&utm_source=footer> >>>>> . >>>>> For more options, visit https://groups.google.com/d/optout. >>>>> >>>> -- >>> You received this message because you are subscribed to the Google >>> Groups "Python Programming for Autodesk Maya" group. >>> To unsubscribe from this group and stop receiving emails from it, send >>> an email to python_inside_maya+unsubscr...@googlegroups.com. >>> To view this discussion on the web visit >>> https://groups.google.com/d/msgid/python_inside_maya/c30a5d56-923b-4edc-a361-67bfa721b8a3%40googlegroups.com >>> <https://groups.google.com/d/msgid/python_inside_maya/c30a5d56-923b-4edc-a361-67bfa721b8a3%40googlegroups.com?utm_medium=email&utm_source=footer> >>> . >>> For more options, visit https://groups.google.com/d/optout. >>> >> -- >> You received this message because you are subscribed to the Google Groups >> "Python Programming for Autodesk Maya" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to python_inside_maya+unsubscr...@googlegroups.com. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/python_inside_maya/CAPCVZ5MOuiNqEFLEAefQGAqR9aZ0QimkWheSfM48CwP3JYid4w%40mail.gmail.com >> <https://groups.google.com/d/msgid/python_inside_maya/CAPCVZ5MOuiNqEFLEAefQGAqR9aZ0QimkWheSfM48CwP3JYid4w%40mail.gmail.com?utm_medium=email&utm_source=footer> >> . >> For more options, visit https://groups.google.com/d/optout. >> > -- > You received this message because you are subscribed to the Google Groups > "Python Programming for Autodesk Maya" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to python_inside_maya+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOA4tqyf7nSU_etJfB%2BcAjEpEuDqjP%2BsO%3DvC3GJ5L5XxxQ%40mail.gmail.com > <https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOA4tqyf7nSU_etJfB%2BcAjEpEuDqjP%2BsO%3DvC3GJ5L5XxxQ%40mail.gmail.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group. To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPCVZ5M_%2BWi0eqFBRjtYTyX1gpoqCaHaqX3Gao%3DfahPMXsKUHg%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.