I would comment on the second part of your question :
Regarding the getNormal() method, the short answer is yes. To write clean
readable code, the only thing that is of importance (more so in python) is
to name your methods, variable with utmost care. Since getNormal() would
return a MVector in both cases (and here I am assuming that your
getCrossProduct() method returns a MVector) it is fine to write that code.
With the name "getNormal" you are making a promise that the method will
return a 'normal' (which here semantically means MVector), as long as you
keep that promise, it is acceptable by all means.

On Tue, Jul 26, 2016 at 1:26 PM, Justin Israel <justinisr...@gmail.com>
wrote:

>
>
> On Tue, Jul 26, 2016 at 1:04 PM likage <dissidia....@gmail.com> wrote:
>
>> Hi all I am trying to do and learn some maya api (I have zero knowledge
>> of them)
>> The following code was taken from an example that I have read online and
>> while testing it out, I have a few questions in mind..
>>
>> 1. In that test() function, as the world_pos variable is calling out to
>> the Point class, how would I know which of the 4 functions in class Point
>> it is trying to call from?
>>
>
> It is calling none of them. Only your __init__() (constructor) is being
> called in your example.
>
>
>> 2. Also, I tried to insert a print statement to show me what type it will
>> return by using type(world_pos), it give me result <class
>> 'spPaint3dContext.Point'> as I was expecting results such as dict, list
>> etc. Then when I insert it into the functions within class, it is telling
>> me that it is part of MVector etc..
>> So, is that any ways that I can expect it to tell me similar like
>> dict/list etc?
>>
>
> Why do you thing it would be returning a list vs a dict vs other? And I
> don't mean these questions in a condescending way. I think it would be good
> to hear your thought process on how you view the way a class works. Then we
> can address the specifics. What do you expect to get back when you
> construct a Point object in different ways? How would you expect to see a
> list vs a dict result? Given that your example never calls any of your 4
> extra methods, how do you envision them being called implicitly?
>
>
>> class Point(object):
>>     def __init__(self, x, y, z):
>>         self.x = x
>>         self.y = y
>>         self.z = z
>>
>>
>>     def asMPoint(self):
>>         return om.MPoint(self.x, self.y, self.z)
>>
>>
>>     def asMFPoint(self):
>>         return om.MFloatPoint(self.x, self.y, self.z)
>>
>>
>>     def asMVector(self):
>>         return om.MVector(self.x, self.y, self.z)
>>
>>
>>     def asMFVector(self):
>>         return om.MFloatVector(self.x, self.y, self.z)
>>
>>
>> def test(v1, v2):
>>     ...
>>     ...
>>     click_pos = om.MPoint()
>>
>>
>>     world_pos = Point(click_pos.x, click_pos.y, click_pos.z)
>>     # Suppose the following values for click _pos x, y and z...
>>     # click_pos.x : -13.2409
>>     # click_pos.y : 44.7756
>>     # click_pos.z : -66.3071
>>
>>
>> This is a bit off-topic but I have this function where it has '2' return
>> variables but they are controlled by this 'smooth' parameter.
>> The reason that this function was wrote it this way was due to a
>> checkbox, thus if it is checked - smooth = True, unchecked - smooth = False
>>
>> Was wondering if this is an acceptable way for me to write it this way?
>> def getNormal(self, smooth = False):
>>     if smooth:
>>         normal = om.MVector()
>>         fn_mesh = om.MFnMesh(self.dagMeshTargetSurface)
>>         fn_mesh.getClosestNormal(self.hitPoint.asMPoint(), normal, om.
>> MSpace.kWorld, None)
>>
>>
>>         return normal
>>     else:
>>         hit_facept = om.MScriptUtil()
>>         om.MScriptUtil().setInt(hit_facept.asIntPtr(),self.hit_face)
>>         itMesh = om.MItMeshPolygon(self.dagMeshTargetSurface)
>>         itMesh.setIndex(self.hit_face, hit_facept.asIntPtr())
>>         triVertsArray = om.MPointArray()
>>         triIndexArray = om.MIntArray()
>>         itMesh.getTriangle(self.hit_triangle, triVertsArray,
>> triIndexArray, om.MSpace.kWorld)
>>
>>
>>         return self.getCrossProduct(triVertsArray[0], triVertsArray[1],
>> triVertsArray[2])
>>
>> --
>> 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/76b30274-4600-4022-a450-90b9c75c399b%40googlegroups.com
>> <https://groups.google.com/d/msgid/python_inside_maya/76b30274-4600-4022-a450-90b9c75c399b%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/CAPGFgA0MGJWSttfnCJxeY_%3DQzqEW63a8dFGUdPiU3576TwHirQ%40mail.gmail.com
> <https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA0MGJWSttfnCJxeY_%3DQzqEW63a8dFGUdPiU3576TwHirQ%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/CAPaTLMR4ULBipc_PAFwJCQLWcUUdSJ%2BXb6tUJzkVB2jmx4F1_w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to