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
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])
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?
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?
--
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_m...@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.
For more options, visit https://groups.google.com/d/optout.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA0MGJWSttfnCJxeY_%3DQzqEW63a8dFGUdPiU3576TwHirQ%40mail.gmail.com.
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?
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.
--
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_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/f055acff-03c5-4a4d-a22e-47cb9c5c8bd2%40googlegroups.com.
I do not have any code to show. This is something that I have copied and paste somewhere..But if say I manage to have some values and I set a variable as 'test.asMPoint()', am I correct to say that it will try to read in 3 values and it will be using the class Point, asMPoint function?And hence my return output will be a MPoint?
Pardon me that this is a very bad example..
--
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_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/34540270-497b-4e5c-be25-cd84dfd16b96%40googlegroups.com.
>>> class Test1 (object):
pass
>>> class Test2 (Test1):
pass
>>> a = Test1()
>>> b = Test2()
>>> type(a) is Test1
True
>>> type(b) is Test2
True
>>> type(b) is Test1
False
>>> isinstance(b, Test1)
True
>>> isinstance(b, Test2)
True
>>> isinstance(a, Test1)
True
>>> isinstance(a, Test2)
False
>>> isinstance([], list)
True
>>> isinstance({}, dict)
True
--
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_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/2b8e970c-a83b-424c-b794-11939e87853e%40googlegroups.com.
Yes exactly. That was the missing bit. You weren't showing the part that you just described.
When you call asMPoint(), you will be creating an instance of MPoint from your instance variables x, y, and z and returning it. It should be pretty obviously what is being called, when you actually call it directly.
current_pt = om.MFloatPoint()
hit_01 = om.MScriptUtil()
hit_02 = om.MScriptUtil()
hit_01.createFromInt(0)
hit_02.createFromInt(0)
...
...
return FindThis(Point(current_pt.x, current_pt.y, current_pt.z), hit_01.getInt(...), ...)
--
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_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/dc9f3aec-5dd7-4a3a-a518-8615bd3da55c%40googlegroups.com.