当前位置: 首页>>代码示例>>Python>>正文


Python OpenMaya.MVector方法代码示例

本文整理汇总了Python中maya.OpenMaya.MVector方法的典型用法代码示例。如果您正苦于以下问题:Python OpenMaya.MVector方法的具体用法?Python OpenMaya.MVector怎么用?Python OpenMaya.MVector使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在maya.OpenMaya的用法示例。


在下文中一共展示了OpenMaya.MVector方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: sample_triangle

# 需要导入模块: from maya import OpenMaya [as 别名]
# 或者: from maya.OpenMaya import MVector [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) 
开发者ID:wiremas,项目名称:spore,代码行数:24,代码来源:spore_sampler.py

示例2: slope_filter

# 需要导入模块: from maya import OpenMaya [as 别名]
# 或者: from maya.OpenMaya import MVector [as 别名]
def slope_filter(self, min_slope, max_slope, fuzz):

        world = om.MVector(0, 1, 0)

        invalid_ids = []
        for i, (_, normal, _, _, _) in enumerate(self.point_data):
            normal = om.MVector(normal[0], normal[1], normal[2])
            angle = math.degrees(normal.angle(world)) + 45 * random.uniform(-fuzz, fuzz)

            if angle < min_slope or angle > max_slope:
                invalid_ids.append(i)

        invalid_ids = sorted(invalid_ids, reverse=True)
        [self.point_data.remove(index) for index in invalid_ids]


        pass 
开发者ID:wiremas,项目名称:spore,代码行数:19,代码来源:spore_sampler.py

示例3: get_rotation

# 需要导入模块: from maya import OpenMaya [as 别名]
# 或者: from maya.OpenMaya import MVector [as 别名]
def get_rotation(self, direction, weight, min_rot, max_rot):
        """ get rotation from a matrix pointing towards the given direction
        slerped by the given weight into the world up vector and added a random
        rotation between min and max rotation """

        r_x = math.radians(random.uniform(min_rot[0], max_rot[0]))
        r_y = math.radians(random.uniform(min_rot[1], max_rot[1]))
        r_z = math.radians(random.uniform(min_rot[2], max_rot[2]))
        util = om.MScriptUtil()
        util.createFromDouble(r_x, r_y, r_z)
        rotation_ptr = util.asDoublePtr()

        matrix = om.MTransformationMatrix()
        matrix.setRotation(rotation_ptr, om.MTransformationMatrix.kXYZ)
        world_up = om.MVector(0, 1, 0)
        rotation = om.MQuaternion(world_up, direction, weight)
        matrix = matrix.asMatrix() * rotation.asMatrix()
        rotation = om.MTransformationMatrix(matrix).rotation().asEulerRotation()

        return om.MVector(math.degrees(rotation.x),
                          math.degrees(rotation.y),
                          math.degrees(rotation.z)) 
开发者ID:wiremas,项目名称:spore,代码行数:24,代码来源:spore_sampler.py

示例4: align_action

# 需要导入模块: from maya import OpenMaya [as 别名]
# 或者: from maya.OpenMaya import MVector [as 别名]
def align_action(self, flag):
        position, normal, tangent = self.get_brush_coords()
        radius = self.brush_state.radius
        neighbour = self.instance_data.get_closest_points(position, radius, self.brush_state.settings['ids'])
        if neighbour:
            self.set_cache_length(len(neighbour))
        else:
            return

        for i, index in enumerate(neighbour):
            rotation = self.instance_data.rotation[index]

            # add to undo stack
            if not self.last_state.has_key(index):
                self.last_state[index] = om.MVector(rotation.x, rotation.y, rotation.z)

            normal = self.instance_data.normal[index]
            direction = self.get_alignment(normal)
            rotation = self.rotate_into(direction, rotation)
            self.rotation.set(rotation, i)

        self.instance_data.set_points(neighbour, rotation=self.rotation)
        self.instance_data.set_state() 
开发者ID:wiremas,项目名称:spore,代码行数:25,代码来源:spore_context.py

示例5: scale_action

# 需要导入模块: from maya import OpenMaya [as 别名]
# 或者: from maya.OpenMaya import MVector [as 别名]
def scale_action(self, flag):
        position, normal, tangent = self.get_brush_coords()
        radius = self.brush_state.radius

        neighbour = self.instance_data.get_closest_points(position, radius, self.brush_state.settings['ids'])
        if neighbour:
            self.set_cache_length(len(neighbour))
        else:
            return

        for i, index in enumerate(neighbour):
            value = self.instance_data.scale[index]
            factor = self.brush_state.settings['scale_factor']
            falloff_weight = self.get_falloff_weight(self.instance_data.position[index])
            factor = (factor - 1) * falloff_weight + 1
            self.scale.set(value * factor, i)

            # add to undo stack
            if not self.last_state.has_key(index):
                self.last_state[index] = om.MVector(value.x, value.y, value.z)

        self.instance_data.set_points(neighbour, scale=self.scale)
        self.instance_data.set_state() 
开发者ID:wiremas,项目名称:spore,代码行数:25,代码来源:spore_context.py

示例6: undo_vector_action

# 需要导入模块: from maya import OpenMaya [as 别名]
# 或者: from maya.OpenMaya import MVector [as 别名]
def undo_vector_action(self, attr, undo_command):
        """ undo transformation attributes.
        scale, rotatio be undone with this method
        :param attr: the instance data attribute that should changed
        :type attr: string
        :param undo_command: a list of index, x, y, z vale, repeating in this pattern
        :type undo_command: list
        :return: """

        if not hasattr(self.instance_data, attr):
            self.logger.error('Instance data has not attribute: {}'.format(attr))
            return

        ids = []
        values = om.MVectorArray()
        for i in range(len(undo_command) / 4):
            ids.append(int(undo_command[i * 4]))
            val_x = float(undo_command[i * 4 + 1])
            val_y = float(undo_command[i * 4 + 2])
            val_z = float(undo_command[i * 4 + 3])
            values.append(om.MVector(val_x, val_y, val_z))

        self.instance_data.set_points(ids, **{attr: values})
        self.instance_data.set_state() 
开发者ID:wiremas,项目名称:spore,代码行数:26,代码来源:spore_context.py

示例7: get_scale

# 需要导入模块: from maya import OpenMaya [as 别名]
# 或者: from maya.OpenMaya import MVector [as 别名]
def get_scale(self, flag, index=0):
        """ get scale values for the currently saved point at the given index """

        # when we in drag mode we want to maintain old scale values
        if self.brush_state.shift_mod and flag != SporeToolCmd.k_click:
            scale = self.initial_scale[index]

        # otherweise we generate new values
        else:
            min_scale = self.brush_state.settings['min_scale']
            max_scale = self.brush_state.settings['max_scale']
            uniform = self.brush_state.settings['uni_scale']
            if uniform:
                scale_x = scale_y = scale_z = random.uniform(min_scale[0], max_scale[0])
            else:
                scale_x = random.uniform(min_scale[0], max_scale[0])
                scale_y = random.uniform(min_scale[1], max_scale[1])
                scale_z = random.uniform(min_scale[2], max_scale[2])

            scale = om.MVector(scale_x, scale_y, scale_z)
            self.initial_scale.set(scale, index)

        return scale 
开发者ID:wiremas,项目名称:spore,代码行数:25,代码来源:spore_context.py

示例8: hit_test

# 需要导入模块: from maya import OpenMaya [as 别名]
# 或者: from maya.OpenMaya import MVector [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) 
开发者ID:wiremas,项目名称:spore,代码行数:27,代码来源:mesh_utils.py

示例9: get_closest_point_and_normal

# 需要导入模块: from maya import OpenMaya [as 别名]
# 或者: from maya.OpenMaya import MVector [as 别名]
def get_closest_point_and_normal(point, target):
    """ find the closest point and normal to the given point
    :return: closest point
             closest normal
             distance to the closest point """

    closest_point = None
    closest_normal = None
    #  shortest_distance = None

    #  for target in targets:
    mesh_fn = get_mesh_fn(target)
    out_point = om.MPoint()
    out_normal = om.MVector()
    mesh_fn.getClosestPointAndNormal(point, out_point, out_normal, om.MSpace.kWorld)
    #  out_tangent = get_tangent(normal)

    return out_point, out_normal 
开发者ID:wiremas,项目名称:spore,代码行数:20,代码来源:mesh_utils.py

示例10: get_tangent

# 需要导入模块: from maya import OpenMaya [as 别名]
# 或者: from maya.OpenMaya import MVector [as 别名]
def get_tangent(normal):
    """ return a normalized tangent for the given normal I
    :param normal MVector: normal vector
    :return MVector: tangent """

    if isinstance(normal, om.MVector):
        u = normal ^ om.MVector(0, 0, 1)
        v = normal ^ om.MVector(0, 1, 0)

        if u.length() > v.length():
            tangent = u.normal()
        else:
            tangent = v.normal()

        return (normal ^ tangent).normal()

    else:
        raise TypeError('Input must be of type MVector, is: {}'.format(type(normal))) 
开发者ID:wiremas,项目名称:spore,代码行数:20,代码来源:mesh_utils.py

示例11: __init__

# 需要导入模块: from maya import OpenMaya [as 别名]
# 或者: from maya.OpenMaya import MVector [as 别名]
def __init__(self, t=datatypes.Matrix()):

        self.transform = t

        d = [t.data[j][i]
             for j in range(len(t.data))
             for i in range(len(t.data[0]))]

        m = OpenMaya.MMatrix()
        OpenMaya.MScriptUtil.createMatrixFromList(d, m)
        m = OpenMaya.MTransformationMatrix(m)

        x = OpenMaya.MVector(1, 0, 0).rotateBy(m.rotation())
        y = OpenMaya.MVector(0, 1, 0).rotateBy(m.rotation())
        z = OpenMaya.MVector(0, 0, 1).rotateBy(m.rotation())

        self.x = datatypes.Vector(x.x, x.y, x.z)
        self.y = datatypes.Vector(y.x, y.y, y.z)
        self.z = datatypes.Vector(z.x, z.y, z.z) 
开发者ID:mgear-dev,项目名称:mgear_core,代码行数:21,代码来源:vector.py

示例12: getNormals

# 需要导入模块: from maya import OpenMaya [as 别名]
# 或者: from maya.OpenMaya import MVector [as 别名]
def getNormals(dag):
    """
    Get the average normal in world space of each vertex on the provided mesh.
    The reason why OpenMaya.MItMeshVertex function has to be used is that the
    MFnMesh class returns incorrect normal results.

    :param OpenMaya.MDagPath dag:
    :return: Normals
    :rtype: list
    """
    # variables
    normals = []

    iter = OpenMaya.MItMeshVertex(dag)
    while not iter.isDone():
        # get normal data
        normal = OpenMaya.MVector()
        iter.getNormal(normal, OpenMaya.MSpace.kWorld)
        normals.append(normal)

        iter.next()

    return normals 
开发者ID:robertjoosten,项目名称:maya-skinning-tools,代码行数:25,代码来源:mesh.py

示例13: closestLineToPoint

# 需要导入模块: from maya import OpenMaya [as 别名]
# 或者: from maya.OpenMaya import MVector [as 别名]
def closestLineToPoint(lines, point):
    """
    Loop over all lines and find the closest point on the line from the
    provided point. After this is done the list of lines is sorted based on
    closest distance to the line.

    :param dict lines:
    :param OpenMaya.MVector point:
    :return: Closest lines and points ordered on distance
    :rtype: tuple
    """
    # get closest point on the line for each line
    names, closestPoints = zip(
        *[
            (name, api.closestPointOnLine(line[0], line[1], point))
            for name, line in lines.iteritems()
        ]
    )

    # sort the closest points from shortest to longest depending on the
    # distance to the vertex in world space position.
    return api.sortByDistance(names, point, closestPoints) 
开发者ID:robertjoosten,项目名称:maya-skinning-tools,代码行数:24,代码来源:joint.py

示例14: generate_reflection_curve

# 需要导入模块: from maya import OpenMaya [as 别名]
# 或者: from maya.OpenMaya import MVector [as 别名]
def generate_reflection_curve(self):
        """Generates a curve which helps creating specular at the desired point
        """
        from maya.OpenMaya import MVector
        from anima.env.mayaEnv import auxiliary

        vtx = pm.ls(sl=1)[0]
        normal = vtx.getNormal(space='world')
        panel = auxiliary.Playblaster.get_active_panel()
        camera = pm.PyNode(pm.modelPanel(panel, q=1, cam=1))
        camera_axis = MVector(0, 0, -1) * camera.worldMatrix.get()

        refl = camera_axis - 2 * normal.dot(camera_axis) * normal

        # create a new curve
        p1 = vtx.getPosition(space='world')
        p2 = p1 + refl

        curve = pm.curve(d=1, p=[p1, p2])

        # move pivot to the first point
        pm.xform(curve, rp=p1, sp=p1) 
开发者ID:eoyilmaz,项目名称:anima,代码行数:24,代码来源:render.py

示例15: boundingBox

# 需要导入模块: from maya import OpenMaya [as 别名]
# 或者: from maya.OpenMaya import MVector [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 
开发者ID:eoyilmaz,项目名称:anima,代码行数:27,代码来源:oyTrajectoryDrawer.py


注:本文中的maya.OpenMaya.MVector方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。