本文整理匯總了Python中maya.OpenMaya.MPoint方法的典型用法代碼示例。如果您正苦於以下問題:Python OpenMaya.MPoint方法的具體用法?Python OpenMaya.MPoint怎麽用?Python OpenMaya.MPoint使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類maya.OpenMaya
的用法示例。
在下文中一共展示了OpenMaya.MPoint方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: sample_triangle
# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MPoint [as 別名]
def sample_triangle(self,triangle_id, point_id):
""" sample a random point on a the given triangle """
r = random.random()
s = random.random()
if r + s >= 1:
r = 1 - r
s = 1 - s
r = om.MScriptUtil(r).asFloat()
s = om.MScriptUtil(s).asFloat()
r = self.geo_cache.AB[triangle_id] * r
s = self.geo_cache.AC[triangle_id] * s
p = om.MPoint(r + s + om.MVector(self.geo_cache.p0[triangle_id]))
u = 0
v = 0
self.point_data.set(point_id, p, self.geo_cache.normals[triangle_id],
self.geo_cache.poly_id[triangle_id], u, v)
示例2: get_screen_position
# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MPoint [as 別名]
def get_screen_position(self, invert_y=True):
""" get the current brush position in screen space coordinates
:param invert_y: inverts the y to convert maya coords to qt coords
qt = True, maya = False
:return: x, y position if draw is True else: None"""
if self.draw:
view = window_utils.active_view()
point = om.MPoint(self.position[0], self.position[1], self.position[2])
x_util = om.MScriptUtil()
x_ptr = x_util.asShortPtr()
y_util = om.MScriptUtil()
y_ptr = y_util.asShortPtr()
view.worldToView(point, x_ptr, y_ptr)
x_pos = x_util.getShort(x_ptr)
y_pos = y_util.getShort(y_ptr)
if invert_y:
y_pos = view.portHeight() - y_pos
return x_pos, y_pos
else:
return None
示例3: hit_test
# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MPoint [as 別名]
def hit_test(target, x, y, invert_y=True):
origin = om.MPoint()
direction = om.MVector()
view = window_utils.active_view()
if invert_y:
y = view.portHeight() - y
view.viewToWorld(x, y, origin, direction)
mesh_fn = get_mesh_fn(target)
if mesh_fn:
points = om.MPointArray()
intersect = mesh_fn.intersect(origin, direction, points, 1.0e-3, om.MSpace.kWorld)
if intersect:
point = points[0]
normal = om.MVector()
mesh_fn.getClosestNormal(point, normal, om.MSpace.kWorld)
tangent = get_tangent(normal)
position = (point.x, point.y, point.z)
tangent = (tangent.x, tangent.y, tangent.z)
normal = (normal.x, normal.y, normal.z)
return (position, normal, tangent)
示例4: boundingBox
# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MPoint [as 別名]
def boundingBox(self):
# get the tPositions
tPositions = self.getTPositions()
# get the multiplier
size = self.getSize()
# create the bounding box
bbox = OpenMaya.MBoundingBox()
# add the positions one by one
numOfTPos = tPositions.length()
#print("numOfTPos in bbox : %s " % numOfTPos)
for i in range(numOfTPos):
# add the positive one
bbox.expand( OpenMaya.MPoint( tPositions[i] + OpenMaya.MVector(size, size, size) ) )
# add the negative one
bbox.expand( OpenMaya.MPoint( tPositions[i] - OpenMaya.MVector(size, size, size) ) )
return bbox
示例5: test_mirror_curve
# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MPoint [as 別名]
def test_mirror_curve(self):
cmds.setAttr("{}.t".format(self.curve), 62, 3, 52)
cmds.setAttr("{}.r".format(self.curve), 162, -231, -10)
other = cmds.createNode("transform")
cmds.setAttr("{}.t".format(other), 1, 2, 3)
cmds.setAttr("{}.r".format(other), 45, 23, 10)
mirrored_curve = control.mirror_curve(self.curve, other)
path_curve = shortcuts.get_dag_path(self.curve)
matrix = path_curve.inclusiveMatrix()
path_other = shortcuts.get_dag_path(other)
inverse_matrix = path_other.inclusiveMatrixInverse()
world_cvs = [OpenMaya.MPoint(x[0], x[1], x[2]) * matrix for x in self.cvs]
for cv in world_cvs:
cv.x *= -1
expected_local_cvs = [p * inverse_matrix for p in world_cvs]
expected_local_cvs = [(p.x, p.y, p.z) for p in expected_local_cvs]
self.cvs_are_equal(mirrored_curve.cvs, expected_local_cvs)
示例6: distance
# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MPoint [as 別名]
def distance(node1=None, node2=None):
"""Calculate the distance between two nodes
:param node1: First node
:param node2: Second node
:return: The distance
"""
if node1 is None or node2 is None:
# Default to selection
selection = cmds.ls(sl=True, type='transform')
if len(selection) != 2:
raise RuntimeError('Select 2 transforms.')
node1, node2 = selection
pos1 = cmds.xform(node1, query=True, worldSpace=True, translation=True)
pos2 = cmds.xform(node2, query=True, worldSpace=True, translation=True)
pos1 = OpenMaya.MPoint(pos1[0], pos1[1], pos1[2])
pos2 = OpenMaya.MPoint(pos2[0], pos2[1], pos2[2])
return pos1.distanceTo(pos2)
示例7: vector_to
# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MPoint [as 別名]
def vector_to(source=None, target=None):
"""Calculate the distance between two nodes
:param source: First node
:param target: Second node
:return: MVector (API2)
"""
if source is None or target is None:
# Default to selection
selection = cmds.ls(sl=True, type='transform')
if len(selection) != 2:
raise RuntimeError('Select 2 transforms.')
source, target = selection
pos1 = cmds.xform(source, query=True, worldSpace=True, translation=True)
pos2 = cmds.xform(target, query=True, worldSpace=True, translation=True)
source = OpenMaya2.MPoint(pos1[0], pos1[1], pos1[2])
target = OpenMaya2.MPoint(pos2[0], pos2[1], pos2[2])
return target - source
示例8: nearestPointOnCurve
# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MPoint [as 別名]
def nearestPointOnCurve(curve, pos):
"""
Find the nearest point on a curve, the function will return
the parameter and point. The point is of type OpenMaya.MPoint.
:param str curve:
:param list pos:
:return: parameter, point
:rtype: float, OpenMaya.MPoint
"""
mFnCurve = api.asMFnNurbsCurve(curve)
pUtil = OpenMaya.MScriptUtil()
pPtr = pUtil.asDoublePtr()
point = mFnCurve.closestPoint(
OpenMaya.MPoint(*pos),
pPtr,
0.001,
OpenMaya.MSpace.kWorld
)
return pUtil.getDouble(pPtr), point
# ----------------------------------------------------------------------------
示例9: evaluate_uvs
# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MPoint [as 別名]
def evaluate_uvs(self):
""" evaluate uv coords for all points in point data.
note: this may take a long time for large meshes """
in_mesh = node_utils.get_connected_in_mesh(self.target, False)
for i, (position, normal, poly_id, u_coord, v_coord) in enumerate(self.point_data):
# if not u_coord and not v_coord:
pos = om.MPoint(position[0], position[1], position[2])
u_coord, v_coord = mesh_utils.get_uv_at_point(in_mesh, pos)
self.point_data.u_coord[i] = u_coord
self.point_data.v_coord[i] = v_coord
示例10: move_action
# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MPoint [as 別名]
def move_action(self, flag):
position, normal, tangent = self.get_brush_coords()
radius = self.brush_state.radius
neighbour = self.instance_data.get_closest_points(position, radius)
if neighbour:
self.set_cache_length(len(neighbour))
else:
return
for i, index in enumerate(neighbour):
position = self.instance_data.position[index]
# add to undo stack
if not self.last_state.has_key(index):
self.last_state[index] = om.MVector(position)
direction = om.MVector(self.brush_state.stroke_direction[0],
self.brush_state.stroke_direction[1],
self.brush_state.stroke_direction[2])
weight = self.brush_state.settings['strength']
falloff = self.get_falloff_weight(position)
position = om.MPoint(position + direction * weight * falloff)
position, normal = mesh_utils.get_closest_point_and_normal(position, self.brush_state.target)
self.position.set(om.MVector(position), i)
self.normal.set(normal, i)
self.instance_data.set_points(neighbour,
position=self.position,
normal=self.normal)
self.instance_data.set_state()
self.instance_data.build_kd_tree()
示例11: get_brush_coords
# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MPoint [as 別名]
def get_brush_coords(self):
""" get current brush position, normal and tangent """
position = om.MPoint(self.brush_state.position[0],
self.brush_state.position[1],
self.brush_state.position[2])
normal = om.MVector(self.brush_state.normal[0],
self.brush_state.normal[1],
self.brush_state.normal[2])
tangent = om.MVector(self.brush_state.tangent[0],
self.brush_state.tangent[1],
self.brush_state.tangent[2])
return position, normal, tangent
示例12: get_closest_points
# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MPoint [as 別名]
def get_closest_points(self, position, radius, exclude=[]):
""" get a list of all indexes within the given radius from the
given position
:param position: MPoint, List, tupe or np.array
:param radius
:param exclude: list of instance ids to exclude from nearest
neighbour search """
if isinstance(position, om.MPoint):
position = (position.x, position.y, position.z)
neighbours = self.tree.query_ball_point(position, radius, eps=radius/10)
if exclude:
instance_ids = np.array([])
for index in neighbours:
instance_ids = np.append(instance_ids, self.instance_id[index])
valid_index = np.array([])
for index in exclude:
valid_index = np.append(valid_index, np.where(instance_ids==index))
neighbours = [neighbours[int(i)] for i in valid_index]
return neighbours
else:
return list(neighbours)
示例13: get_uv_at_point
# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MPoint [as 別名]
def get_uv_at_point(target, point, uv_set=None, poly_id=None):
""" get closest UV coords of the target at the given point
:param target str: name of the target object
:param point MPoint: """
util = om.MScriptUtil()
uv_coords_ptr = util.asFloat2Ptr()
mesh_fn = get_mesh_fn(target)
mesh_fn.getUVAtPoint(point, uv_coords_ptr, om.MSpace.kObject, uv_set, poly_id)
u_coord = util.getFloat2ArrayItem(uv_coords_ptr, 0, 0)
v_coord = util.getFloat2ArrayItem(uv_coords_ptr, 0, 1)
return u_coord, v_coord
示例14: create_brush_shape
# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MPoint [as 別名]
def create_brush_shape(self):
""" generate the shape of the brush based on the brush state """
if self.brush_state.draw:
# fetch point and normal
pnt = om.MPoint(self.brush_state.position[0],
self.brush_state.position[1],
self.brush_state.position[2])
nrm = om.MVector(self.brush_state.normal[0],
self.brush_state.normal[1],
self.brush_state.normal[2])
tan = om.MVector(self.brush_state.tangent[0],
self.brush_state.tangent[1],
self.brush_state.tangent[2])
# get point at normal and tangent
# n_pnt = pnt + (nrm * self._state.radius * 0.75)
# t_str = pnt + (tan * self._state.radius * 0.75)
# t_end = pnt + (tan * self._state.radius)
# shape.append(window_utils.world_to_view(pnt))
shape = []
# get circle points
theta = math.radians(360 / 20)
for i in xrange(40 + 1):
rot = om.MQuaternion(theta * i, nrm)
rtan = tan.rotateBy(rot)
pos = pnt + (rtan * self.brush_state.radius)
pos_x, pos_y = window_utils.world_to_view(pos)
shape.append((pos_x, pos_y))
return [shape]
示例15: getAveragePosition
# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MPoint [as 別名]
def getAveragePosition(dag, component, space):
"""
Get average position of connected vertices.
:param OpenMaya.MDagPath dag:
:param OpenMaya.MFnSingleIndexedComponent component:
:param OpenMaya.MSpace space:
:return: Average length of the connected edges
:rtype: OpenMaya.MPoint
"""
averagePos = OpenMaya.MPoint()
# get connected vertices
connected = OpenMaya.MIntArray()
iterate = OpenMaya.MItMeshVertex(dag, component)
iterate.getConnectedVertices(connected)
# get original position
originalPos = iterate.position(space)
# ignore if no vertices are connected
if not connected.length():
return averagePos
# get average
component = asComponent(connected)
iterate = OpenMaya.MItMeshVertex(dag, component)
while not iterate.isDone():
averagePos += OpenMaya.MVector(iterate.position(space))
iterate.next()
averagePos = averagePos/connected.length()
return originalPos, averagePos