當前位置: 首頁>>代碼示例>>Python>>正文


Python OpenMaya.MQuaternion方法代碼示例

本文整理匯總了Python中maya.OpenMaya.MQuaternion方法的典型用法代碼示例。如果您正苦於以下問題:Python OpenMaya.MQuaternion方法的具體用法?Python OpenMaya.MQuaternion怎麽用?Python OpenMaya.MQuaternion使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在maya.OpenMaya的用法示例。


在下文中一共展示了OpenMaya.MQuaternion方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: get_rotation

# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MQuaternion [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

示例2: _get_rotation_quaternion

# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MQuaternion [as 別名]
def _get_rotation_quaternion(self):
        obj=OpenMaya.MObject()
        #make a object of type MSelectionList
        sel_list=OpenMaya.MSelectionList()
        #add something to it
        #you could retrieve this from function or the user selection
        sel_list.add(self.maya_node)
        #fill in the MObject
        sel_list.getDependNode(0,obj)
        #check if its a transform
        if (obj.hasFn(OpenMaya.MFn.kTransform)):
            quat = OpenMaya.MQuaternion()
            #then we can add it to transfrom Fn
            #Fn is basically the collection of functions for given objects
            xform=OpenMaya.MFnTransform(obj)
            xform.getRotation(quat)
            # glTF requires normalize quat
            quat.normalizeIt()
        
        py_quat = [quat[x] for x in range(4)]
        return py_quat 
開發者ID:matiascodesal,項目名稱:maya-glTF,代碼行數:23,代碼來源:glTFExport.py

示例3: getCircleData

# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MQuaternion [as 別名]
def getCircleData(self, origin, normal, tangent, scale ):
        """creates the circleData
        """
        quat = OpenMaya.MQuaternion()
        # create the circle data
        circleData = [] * 0
        
        for i in range(self.circleDivision):
            quat.setAxisAngle( normal.normal() , float(i) * self.unitAngle )
            pointOnCircle = tangent.rotateBy( quat )
            
            circleData.append( [pointOnCircle.x * scale + origin.x, pointOnCircle.y * scale + origin.y, pointOnCircle.z * scale + origin.z] )
        
        # close the circle
        # append the first to last
        circleData.append( circleData[0] )
        
        return circleData 
開發者ID:eoyilmaz,項目名稱:anima,代碼行數:20,代碼來源:oyTrajectoryDrawer.py

示例4: rotate_into

# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MQuaternion [as 別名]
def rotate_into(self, direction, rotation):
        """ slerp the given rotation values into the direction given
        by the brush_state
        @param direction MVector: the target direction
        @param rotation MVector: current euler rotation """

        vector_weight = self.brush_state.settings['strength']
        up_vector = om.MVector(0, 1, 0)
        local_up = up_vector.rotateBy(om.MEulerRotation(math.radians(rotation.x),
                                                        math.radians(rotation.y),
                                                        math.radians(rotation.z)))

        target_rotation = om.MQuaternion(local_up, direction, vector_weight)

        util = om.MScriptUtil()
        x_rot = np.radians(rotation.x)
        y_rot = np.radians(rotation.y)
        z_rot = np.radians(rotation.z)
        util.createFromDouble(x_rot, y_rot, z_rot)
        rotation_ptr = util.asDoublePtr()
        mat = om.MTransformationMatrix()
        mat.setRotation(rotation_ptr, om.MTransformationMatrix.kXYZ)

        mat = mat.asMatrix() * target_rotation.asMatrix()
        rotation = om.MTransformationMatrix(mat).rotation()

        return om.MVector(math.degrees(rotation.asEulerRotation().x),
                        math.degrees(rotation.asEulerRotation().y),
                        math.degrees(rotation.asEulerRotation().z)) 
開發者ID:wiremas,項目名稱:spore,代碼行數:31,代碼來源:spore_context.py

示例5: get_rotation

# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MQuaternion [as 別名]
def get_rotation(initial_rotation, dir_vector, vector_weight):
    """ Get euler rotation values based on given min/max rotation, a direction
    vector and a weight for the given vector. slerp between direction vector and
    world up vector.
    :param min_rotation tuple(x,y,z): minimum rotation values
    :param max_rotation tuple(x,y,z): maximum rotation values
    :param dir_vector MVector: direction of instance y-up
    :param weight float(0-1): the weigth of the direction
    :return MVector: Mvector containing euler rotation values """

    world_up = om.MVector(0, 1, 0)
    rotation = om.MQuaternion(world_up, dir_vector, vector_weight)

    # get random rotation
    #  r_x = math.radians(random.uniform(min_rotation[0], max_rotation[0]))
    #  r_y = math.radians(random.uniform(min_rotation[1], max_rotation[1]))
    #  r_z = math.radians(random.uniform(min_rotation[2], max_rotation[2]))

    mat = om.MTransformationMatrix()

    util = om.MScriptUtil()
    util.createFromDouble(initial_rotation[0], initial_rotation[1], initial_rotation[2])
    rotation_ptr = util.asDoublePtr()
    mat.setRotation(rotation_ptr, om.MTransformationMatrix.kXYZ)

    mat = mat.asMatrix() * rotation.asMatrix()
    rotation = om.MTransformationMatrix(mat).rotation()

    return om.MVector(math.degrees(rotation.asEulerRotation().x),
                      math.degrees(rotation.asEulerRotation().y),
                      math.degrees(rotation.asEulerRotation().z)) 
開發者ID:wiremas,項目名稱:spore,代碼行數:33,代碼來源:brush_utils.py

示例6: rotateAlongAxis

# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MQuaternion [as 別名]
def rotateAlongAxis(v, axis, a):
    """Rotate a vector around a given axis defined by other vector.

    Arguments:
        v (vector): The vector to rotate.
        axis (vector): The axis to rotate around.
        a (float): The rotation angle in radians.

    """
    sa = math.sin(a / 2.0)
    ca = math.cos(a / 2.0)

    q1 = OpenMaya.MQuaternion(v.x, v.y, v.z, 0)
    q2 = OpenMaya.MQuaternion(axis.x * sa, axis.y * sa, axis.z * sa, ca)
    q2n = OpenMaya.MQuaternion(-axis.x * sa, -axis.y * sa, -axis.z * sa, ca)
    q = q2 * q1
    q *= q2n

    out = OpenMaya.MVector(q.x, q.y, q.z)

    return out


##########################################################
# CLASS
########################################################## 
開發者ID:mgear-dev,項目名稱:mgear_core,代碼行數:28,代碼來源:vector.py

示例7: get_rotation

# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MQuaternion [as 別名]
def get_rotation(self, flag, normal, index=0):
        """ generate new rotation values based on the brush state
        if we are in drag mode we maintain old rotation values and adjust
        rotation to the new normal. we can use the index arg to set a
        specific index for the last placed objects """

        dir_vector = self.get_alignment(normal)
        vector_weight = self.brush_state.settings['strength']
        world_up = om.MVector(0, 1, 0)
        rotation = om.MQuaternion(world_up, dir_vector, vector_weight)

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

        # otherwise we generate new values
        else:
            # get random rotation
            min_rotation = self.brush_state.settings['min_rot']
            max_rotation = self.brush_state.settings['max_rot']
            r_x = math.radians(random.uniform(min_rotation[0], max_rotation[0]))
            r_y = math.radians(random.uniform(min_rotation[1], max_rotation[1]))
            r_z = math.radians(random.uniform(min_rotation[2], max_rotation[2]))
            self.initial_rotation.set(om.MVector(r_x, r_y, r_z), index)
            initial_rotation = self.initial_rotation[index]
            #  rotation = brush_utils.get_rotation(self.initial_rotation, direction,

        mat = om.MTransformationMatrix()

        util = om.MScriptUtil()
        util.createFromDouble(initial_rotation.x,
                              initial_rotation.y,
                              initial_rotation.z)
        rotation_ptr = util.asDoublePtr()
        mat.setRotation(rotation_ptr, om.MTransformationMatrix.kXYZ)

        mat = mat.asMatrix() * rotation.asMatrix()
        rotation = om.MTransformationMatrix(mat).rotation()

        return om.MVector(math.degrees(rotation.asEulerRotation().x),
                        math.degrees(rotation.asEulerRotation().y),
                        math.degrees(rotation.asEulerRotation().z)) 
開發者ID:wiremas,項目名稱:spore,代碼行數:44,代碼來源:spore_context.py

示例8: create_brush_shape

# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MQuaternion [as 別名]
def create_brush_shape(self):

        if self.draw:
            # fetch point and normal
            pnt = om.MPoint(self.position[0],
                            self.position[1],
                            self.position[2])
            nrm = om.MVector(self.normal[0],
                            self.normal[1],
                            self.normal[2])
            tan = om.MVector(self.tangent[0],
                            self.tangent[1],
                            self.tangent[2])

            # draw dragger shapes
            if self.shift_mod:
                pos_x, pos_y = self.world_to_view(pnt)

                shapes = []
                shapes.append([(pos_x - 15, pos_y - 15), (pos_x + 15, pos_y + 15)])
                shapes.append([(pos_x - 15, pos_y + 15), (pos_x + 15, pos_y - 15)])
                return shapes


            else:
                # 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)

                # get circle points
                theta = math.radians(360 / 20)
                shape = []
                for i in xrange(20 + 1):
                    rot = om.MQuaternion(theta * i, nrm)
                    rtan = tan.rotateBy(rot)
                    pos = pnt + (rtan * self._radius)

                    pos_x, pos_y = self.world_to_view(pos)
                    shape.append((pos_x, pos_y))

                return [shape] 
開發者ID:wiremas,項目名稱:spore,代碼行數:44,代碼來源:brush_state.py

示例9: slerp

# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MQuaternion [as 別名]
def slerp(qa, qb, t):
    """Calculates the quaternion slerp between two quaternions.

    From: http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/index.htm

    :param qa: Start MQuaternion.
    :param qb: End MQuaternion.
    :param t: Parameter between 0.0 and 1.0
    :return: An MQuaternion interpolated between qa and qb.
    """
    qm = OpenMaya.MQuaternion()

    # Calculate angle between them.
    cos_half_theta = qa.w * qb.w + qa.x * qb.x + qa.y * qb.y + qa.z * qb.z
    # if qa == qb or qa == -qb then theta = 0 and we can return qa
    if abs(cos_half_theta) >= 1.0:
        qm.w = qa.w
        qm.x = qa.x
        qm.y = qa.y
        qm.z = qa.z
        return qa

    # Calculate temporary values
    half_theta = math.acos(cos_half_theta)
    sin_half_theta = math.sqrt(1.0 - cos_half_theta * cos_half_theta)
    # if theta = 180 degrees then result is not fully defined
    # we could rotate around any axis normal to qa or qb
    if math.fabs(sin_half_theta) < 0.001:
        qm.w = qa.w * 0.5 + qb.w * 0.5
        qm.x = qa.x * 0.5 + qb.x * 0.5
        qm.y = qa.y * 0.5 + qb.y * 0.5
        qm.z = qa.z * 0.5 + qb.z * 0.5
        return qm

    ratio_a = math.sin((1 - t) * half_theta) / sin_half_theta
    ratio_b = math.sin(t * half_theta) / sin_half_theta
    # Calculate quaternion
    qm.w = qa.w * ratio_a + qb.w * ratio_b
    qm.x = qa.x * ratio_a + qb.x * ratio_b
    qm.y = qa.y * ratio_a + qb.y * ratio_b
    qm.z = qa.z * ratio_a + qb.z * ratio_b
    return qm 
開發者ID:chadmv,項目名稱:cmt,代碼行數:44,代碼來源:swingtwist.py


注:本文中的maya.OpenMaya.MQuaternion方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。