Re: [Maya-Python] MMeshIntersector: Getting world position / matrix of point in object space

2018-08-04 Thread Cedric Bazillou
tips wise maybe just put your code into a function so the garbage collector 
can clean up intermediate elements?

-- 
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/b17d5eb1-202e-43fc-8b00-cb87dc530148%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Maya-Python] MMeshIntersector: Getting world position / matrix of point in object space

2018-08-04 Thread igo rov
...yes thats true, and I wasnt`t expecting that there could be a bug in the
API :)  Deciding for api 1.0 or 2.0 ist not too easy.
I know the courses of cgcircuit, but for python. Hopefully taking the next
step to c++ won`t bee too hard for somebody coming more from the artist
side of maya. Though I will stick with python also, and defintely come back
here soon.

2018-08-04 18:08 GMT+02:00 Luiz Amaral :

> Hey igo, happy to see you solved the puzzle! Its such a great feeling to
> have our tools working. Specially after some struggle ;)
>
> Maya API can be tricky sometimes.
>
> I highly recomend Chad Vernon’s courses on cgcircuit for learning c++ API
>
> https://www.cgcircuit.com/
>
>  http://www.chadvernon.com/blog/resources/maya-api-programming/
>
> Good luck and enjoy the ride :D
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Python Programming for Autodesk Maya" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/
> topic/python_inside_maya/zGdhBD6SuUE/unsubscribe.
> To unsubscribe from this group and all its topics, 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/02874409-af3c-4fc9-afa2-
> 083f3cf40a95%40googlegroups.com.
> 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/CANAXgk-JKK34Rr02TdRabLPwgnbDTesjF4e%3DE6j-SUUWWHhEDg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Maya-Python] MMeshIntersector: Getting world position / matrix of point in object space

2018-08-04 Thread Luiz Amaral
Hey igo, happy to see you solved the puzzle! Its such a great feeling to have 
our tools working. Specially after some struggle ;)

Maya API can be tricky sometimes.

I highly recomend Chad Vernon’s courses on cgcircuit for learning c++ API 

https://www.cgcircuit.com/

 http://www.chadvernon.com/blog/resources/maya-api-programming/

Good luck and enjoy the ride :D

-- 
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/02874409-af3c-4fc9-afa2-083f3cf40a95%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Maya-Python] MMeshIntersector: Getting world position / matrix of point in object space

2018-08-03 Thread igo rov
Hi again,

I don`t know how much sense this code still makes, however for me its for 
learning purposes and for me its one step towards my goal to learn c++ api. 
Especially converting between vectors, MFloatPoint and Matrix type might be 
horrible code...but I didn*t find a more direct way.at least it works 
for me.
If you have some hints for me, how to do things more clever, please don`t 
hesitate

import maya.OpenMaya as om

selList = om.MSelectionList()
selList.add("pCube1")
dagCube = om.MDagPath()
selList.getDagPath(0, dagCube)
mesh = dagCube.child(0)
trFn = om.MFnTransform(dagCube)
matrCube = trFn.transformationMatrix()
##
mesh.apiTypeStr() # should be kMesh
##
intersector = om.MMeshIntersector()
intersector.create(mesh, matrCube) # no error in API 1.0...Yeah ;)

selListLoc1 = om.MSelectionList()
selListLoc1.add("locator1")
dagLoc1 = om.MDagPath()
selListLoc1.getDagPath(0, dagLoc1)
trFnLoc1 = om.MFnTransform(dagLoc1)
vecLoc1 = trFnLoc1.translation(4)
pointLoc1 = om.MPoint(vecLoc1.x, vecLoc1.y, vecLoc1.z)
mPointOnMesh = om.MPointOnMesh()
intersector.getClosestPoint(pointLoc1,mPointOnMesh, 1000)
resultPoint = mPointOnMesh.getPoint()

# first I create vector
resultVector = om.MVector(resultPoint.x, resultPoint.y,resultPoint.z)

# then I convert to matrix
matrTrans = om.MTransformationMatrix()
matrTrans.setTranslation(resultVector,4)
localMatrix = matrTrans.asMatrix(1)
# this is the important step to get the world matrix, multiply child/local 
with the parent Matrix
worldMatr = localMatrix*matrCube
worldMatrTrans = om.MTransformationMatrix(worldMatr)

selListLoc2 = om.MSelectionList()
selListLoc2.add("locator2")
dagLoc2 = om.MDagPath()
selListLoc2.getDagPath(0, dagLoc2)
trFnLoc2 = om.MFnTransform(dagLoc2)
trFnLoc2.set(worldMatrTrans)

-- 
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/55ad67e8-62b9-48a5-8155-4bc90a7de78f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Maya-Python] MMeshIntersector: Getting world position / matrix of point in object space

2018-08-03 Thread Luiz Amaral

import maya.openmaya as om

-- 
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/a13fe09e-54fb-414a-9496-175a3539fc9a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Maya-Python] MMeshIntersector: Getting world position / matrix of point in object space

2018-08-03 Thread Luiz Amaral
Yeah good one! Try with the api 1.0

-- 
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/55bd6124-2aec-4898-b5fb-9dd5931fce6e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Maya-Python] MMeshIntersector: Getting world position / matrix of point in object space

2018-08-02 Thread Cedric Bazillou
Hi guys ,
normally by design the closest point value returned by the intersector is 
in object space
http://help.autodesk.com/view/MAYAUL/2017/ENU/?guid=__cpp_ref_closest_point_cmd_2closest_point_cmd_8cpp_example_html

in the function closestPointCmd::createDisplay( MPointOnMesh 
&
 
info, MMatrix 
&
 
matrix )
we go from local to worldspace by applying the mesh parent transform ( and 
its what is used as well for the matrix initialization.) is quite horrible 
that they labelled a local point as world point though..

i would as well stay as far as possible from the OpenMaya 2 layer if i can 
as you will soon see some hidden bugs and only 30 percent of the function 
are exposed ( dont concern yourself with pythonic argument as you will need 
to convert your code to c++ if your are serious about your work)

Le jeudi 2 août 2018 15:34:56 UTC-4, Luiz Amaral a écrit :
>
> OK I’m out of ideas now :/

-- 
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/7aed4d19-7f93-415d-8f83-50a98dad7f4c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Maya-Python] MMeshIntersector: Getting world position / matrix of point in object space

2018-08-02 Thread Luiz Amaral
OK I’m out of ideas now :/

-- 
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/d49e25b8-3d57-47d9-8bb5-c0af4442cff1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Maya-Python] MMeshIntersector: Getting world position / matrix of point in object space

2018-08-02 Thread igo rov
I get the same error

-- 
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/16e2c4e6-565a-41f8-b559-83c20ac28095%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Maya-Python] MMeshIntersector: Getting world position / matrix of point in object space

2018-08-02 Thread Luiz Amaral
Try this

meshIntersect.create(mesh, om2.MMatrix(matr))

-- 
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/9e6d8b5d-32d6-4bcc-b359-41b81a665a86%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Maya-Python] MMeshIntersector: Getting world position / matrix of point in object space

2018-08-02 Thread igo rov
Can you execute this:

import maya.api.OpenMaya as om2

selList = om2.MGlobal.getActiveSelectionList()
dag = selList.getDagPath(0)
matr = dag.inclusiveMatrix()
mesh = dag.child(0)
meshIntersect = om2.MMeshIntersector()
meshIntersect.create(mesh, matr)


I get an error, because it won`t accept the "matr" argument

Am Donnerstag, 2. August 2018 02:19:20 UTC+2 schrieb Luiz Amaral:
>
> You should at least pass the identity matrix like this
>
> meshIntersect.create(mesh, om2.MMatrix.identity)
>

-- 
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/6455b845-aa61-4458-932b-867c1c16c895%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Maya-Python] MMeshIntersector: Getting world position / matrix of point in object space

2018-08-01 Thread Luiz Amaral
You should at least pass the identity matrix like this

meshIntersect.create(mesh, om2.MMatrix.identity)

-- 
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/fab96010-ac16-49c7-8452-68851e98f0d3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Maya-Python] MMeshIntersector: Getting world position / matrix of point in object space

2018-08-01 Thread Luiz Amaral
Try this

matr = om2.MMatrix(dag.inclusiveMatrix())
meshIntersect.create(mesh, matr)

-- 
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/5d3acb67-af64-44b9-9871-aea7967bae66%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Maya-Python] MMeshIntersector: Getting world position / matrix of point in object space

2018-08-01 Thread igo rov
Hi,
as for the missing Matrix parameter, there is this thread:
https://groups.google.com/forum/#!topic/python_inside_maya/axX7W8imeEU

I have the same problems as described there, if I pass the matrix I will
get this error: More keyword list entries (4) than format specifiers (2)

But you are right, there has to be a Matrix parameter as the documentation
says:.

then the matrix passed to create() should provide the mapping
from world space to the mesh's object space.


So for me the MMeshIntersector is not working

2018-08-01 23:47 GMT+02:00 Luiz Amaral :

> Hey there,
>
> “ ‘Point’ Specifies the location for which to evaluate the closest point
> on the mesh. `point' is transformed using the matrix parameter passed to
> the create() method, so for example if your matrix maps world to object
> space, then `point' should be specified in world space.”
>
> You should either pass the cube’s world matrix on creation or pass the
> point localized to the cube’s space on get closest point.
>
> Since you created the MMeshIntercector without passing a matrix to it the
> get closest point function expects a localized position.
>
> That’s why you are getting a “random” point instead of the closest point
> to locator2.
>
> If you pass the cube’s world matrix to the create just multiply the result
> of the get closest point by the same matrix and your locator will snap to
> the expected place.
>
> Or you can keep create the way it is and multiply the point by the inverse
> of the cube’s world matrix before passing it to the get closest point and
> then multiply the result by the world matrix again.
>
> Cheers,
>
> Luiz
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Python Programming for Autodesk Maya" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/
> topic/python_inside_maya/zGdhBD6SuUE/unsubscribe.
> To unsubscribe from this group and all its topics, 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/82d9cdd0-b19f-4da4-b36d-
> 883ef7f86deb%40googlegroups.com.
> 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/CANAXgk8_jZvjo2%3Dp0jvNk06iWC_Oq584yEiUv%2BeS8Z12HSt5Cg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.