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


Python OpenMaya.MFnNurbsCurve方法代碼示例

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


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

示例1: getCurveFn

# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MFnNurbsCurve [as 別名]
def getCurveFn(self):
        inputCurvePlug = OpenMaya.MPlug(self.thisMObject(), instanceAlongCurveLocator.inputCurveAttr)
        curve = getSingleSourceObjectFromPlug(inputCurvePlug)

        # Get Fn from a DAG path to get the world transformations correctly
        if curve is not None:
            path = OpenMaya.MDagPath()
            trFn = OpenMaya.MFnDagNode(curve)
            trFn.getPath(path)

            path.extendToShape()

            if path.node().hasFn(OpenMaya.MFn.kNurbsCurve):
                return OpenMaya.MFnNurbsCurve(path)

        return None

    # Calculate expected instances by the instancing mode 
開發者ID:mmerchante,項目名稱:instanceAlongCurve,代碼行數:20,代碼來源:instanceAlongCurve.py

示例2: asMFnNurbsCurve

# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MFnNurbsCurve [as 別名]
def asMFnNurbsCurve(curve):
    """
    Convert a node into a OpenMaya.MFnNurbsCurve.

    :param str node:
    :return: MFnNurbsCurve of parsed curve
    :rtype: OpenMaya.MFnNurbsCurve
    """
    dag = toMDagPath(curve)
    nurbsCurveFn = OpenMaya.MFnNurbsCurve(dag)

    return nurbsCurveFn 
開發者ID:robertjoosten,項目名稱:maya-spline-ik,代碼行數:14,代碼來源:api.py

示例3: getCurveParamAtPosition

# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MFnNurbsCurve [as 別名]
def getCurveParamAtPosition(crv, position):
    """Get curve parameter from a position

    Arguments:
        position (list of float): Represents the position in worldSpace
            exp: [1.4, 3.55, 42.6]
        crv (curve): The  source curve to get the parameter.

    Returns:
        list: paramenter and curve length
    """
    point = om.MPoint(position[0], position[1], position[2])

    dag = om.MDagPath()
    obj = om.MObject()
    oList = om.MSelectionList()
    oList.add(crv.name())
    oList.getDagPath(0, dag, obj)

    curveFn = om.MFnNurbsCurve(dag)
    length = curveFn.length()
    crv.findParamFromLength(length)

    paramUtill = om.MScriptUtil()
    paramPtr = paramUtill.asDoublePtr()

    point = curveFn.closestPoint(point, paramPtr, 0.001, om.MSpace.kObject)
    curveFn.getParamAtPoint(point, paramPtr, 0.001, om.MSpace.kObject)

    param = paramUtill.getDouble(paramPtr)

    return param, length 
開發者ID:mgear-dev,項目名稱:mgear_core,代碼行數:34,代碼來源:curve.py

示例4: editCurve

# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MFnNurbsCurve [as 別名]
def editCurve(parent, points, degree=1, form=kOpen):
    assert isinstance(parent, DagNode), (
        "parent must be of type cmdx.DagNode"
    )

    degree = min(3, max(1, degree))

    cvs = om1.MPointArray()
    curveFn = om1.MFnNurbsCurve()

    for point in points:
        cvs.append(om1.MPoint(*point))

    mobj = curveFn.createWithEditPoints(cvs,
                                        degree,
                                        form,
                                        False,
                                        False,
                                        True,
                                        _encode1(parent.path()))

    mod = om1.MDagModifier()
    mod.renameNode(mobj, parent.name(namespace=True) + "Shape")
    mod.doIt()

    def undo():
        mod.deleteNode(mobj)
        mod.doIt()

    def redo():
        mod.undoIt()

    commit(undo, redo)

    shapeFn = om1.MFnDagNode(mobj)
    return encode(shapeFn.fullPathName()) 
開發者ID:mottosso,項目名稱:cmdx,代碼行數:38,代碼來源:cmdx.py

示例5: NurbsCurveData

# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MFnNurbsCurve [as 別名]
def NurbsCurveData(points, degree=1, form=om1.MFnNurbsCurve.kOpen):
    """Tuple of points to MObject suitable for nurbsCurve-typed data

    Arguments:
        points (tuple): (x, y, z) tuples per point
        degree (int, optional): Defaults to 1 for linear
        form (int, optional): Defaults to MFnNurbsCurve.kOpen,
            also available kClosed

    Example:
        Create a new nurbs curve like this.

        >>> data = NurbsCurveData(
        ...     points=(
        ...         (0, 0, 0),
        ...         (0, 1, 0),
        ...         (0, 2, 0),
        ...     ))
        ...
        >>> parent = createNode("transform")
        >>> shape = createNode("nurbsCurve", parent=parent)
        >>> shape["cached"] = data

    """

    degree = min(3, max(1, degree))

    cvs = om1.MPointArray()
    curveFn = om1.MFnNurbsCurve()
    data = om1.MFnNurbsCurveData()
    mobj = data.create()

    for point in points:
        cvs.append(om1.MPoint(*point))

    curveFn.createWithEditPoints(cvs,
                                 degree,
                                 form,
                                 False,
                                 False,
                                 True,
                                 mobj)

    return mobj 
開發者ID:mottosso,項目名稱:cmdx,代碼行數:46,代碼來源:cmdx.py

示例6: compute

# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MFnNurbsCurve [as 別名]
def compute(self, plug, dataBlock):
        if plug == closestPointOnCurve.aOutPosition or plug == closestPointOnCurve.aOutParam:
            dataHandle = dataBlock.inputValue(closestPointOnCurve.aInCurve)
            inputAsCurve = dataHandle.asNurbsCurve()
            
            #if not inputAsCurve.hasFn(OpenMaya.MFn.kNurbsCurve):
            #    return OpenMaya.kUnknownParameter
            
            dataHandle = dataBlock.inputValue(closestPointOnCurve.aInPosition)
            
            inPositionAsFloat3 = dataHandle.asFloat3()
            inPosition = OpenMaya.MPoint(
                inPositionAsFloat3[0],
                inPositionAsFloat3[1],
                inPositionAsFloat3[2]
            )
            
            # connect the MFnNurbsCurve
            # and ask the closest point
            
            nurbsCurveFn = OpenMaya.MFnNurbsCurve(inputAsCurve)
            
            # get and set outPosition
            outParam = OpenMaya.MScriptUtil()
            outParam.createFromDouble(0)
            outParamPtr = outParam.asDoublePtr() 
            
            # get position and paramater
            outPosition = nurbsCurveFn.closestPoint(
                inPosition, True, outParamPtr, 0.001, OpenMaya.MSpace.kWorld
            )
            
            outputHandle = dataBlock.outputValue(
                closestPointOnCurve.aOutPosition
            )
            outputHandle.set3Float(outPosition.x, outPosition.y, outPosition.z)
            
            # get and set outNormal
            #outNormal = nurbsCurveFn.normal(parameter, OpenMaya.MSpace.kWorld)
            #outputHandle = dataBlock.outputValue(closestPointOnCurve.aOutNormal)
            #outputHandle.set3Float(outNormal.x, outNormal.y, outNormal.z)
            #outputHandle.set3Float(0, 1, 0 )
            
            # get and set the uvs
            outputHandle = dataBlock.outputValue(closestPointOnCurve.aOutParam)
            #outputHandle.setFloat(OpenMaya.MScriptUtil(outParamPtr).asDouble())
            outputHandle.setFloat(OpenMaya.MScriptUtil.getDouble(outParamPtr))
            
            dataBlock.setClean(plug)
        else:
            return OpenMaya.kUnknownParameter

# creator 
開發者ID:eoyilmaz,項目名稱:anima,代碼行數:55,代碼來源:closestPointOnCurve.py

示例7: getRotationForParam

# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MFnNurbsCurve [as 別名]
def getRotationForParam(self, param, axisHandlesSorted, curveForm, curveMaxParam):

        indexRange = (-1, -1)
        wrapAround = not (curveForm is OpenMaya.MFnNurbsCurve.kOpen)

        # Find the range of indices that make up this curve segment
        for i in xrange(len(axisHandlesSorted)):

            # TODO: could use a binary search
            if param < axisHandlesSorted[i][1]:

                if i > 0:
                    indexRange = (i - 1, i)
                    break
                elif wrapAround:
                    indexRange = (len(axisHandlesSorted) - 1, 0)
                    break
                else:
                    indexRange = (0, 0)
                    break

        # Edge case
        if indexRange[0] == -1 and indexRange[1] == -1 and len(axisHandlesSorted) > 0:
            if wrapAround:
                indexRange = (len(axisHandlesSorted) - 1, 0)
            else:
                indexRange = (len(axisHandlesSorted) - 1, len(axisHandlesSorted) - 1)
            
        # Now find the lerp value based on the range
        if indexRange[0] > -1 and indexRange[1] > -1:
            minParam = axisHandlesSorted[indexRange[0]][1]
            maxParam = axisHandlesSorted[indexRange[1]][1]

            minAxis = axisHandlesSorted[indexRange[0]][2]
            maxAxis = axisHandlesSorted[indexRange[1]][2]

            if(math.fabs(minParam - maxParam) > 0.001):

                if minParam > maxParam and wrapAround:

                    if param < maxParam:
                        param = param + curveMaxParam

                    maxParam = maxParam + curveMaxParam
                
                t = min(max((param - minParam) / (maxParam - minParam), 0.0), 1.0)

                return minAxis + (maxAxis - minAxis) * t

            return minAxis

        return 0.0 
開發者ID:mmerchante,項目名稱:instanceAlongCurve,代碼行數:54,代碼來源:instanceAlongCurve.py

示例8: compute

# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MFnNurbsCurve [as 別名]
def compute(self, plug, dataBlock):
        try:
            curveDataHandle = dataBlock.inputValue(instanceAlongCurveLocator.inputCurveAttr)
            curve = curveDataHandle.asNurbsCurveTransformed()

            updateTranslation = (plug == instanceAlongCurveLocator.outputTranslationAttr.compound)
            updateRotation = (plug == instanceAlongCurveLocator.outputRotationAttr.compound)
            updateScale = (plug == instanceAlongCurveLocator.outputScaleAttr.compound)

            if not curve.isNull():

                if updateTranslation or updateRotation or updateScale:
                    curveFn = OpenMaya.MFnNurbsCurve(curve)

                    instanceCount = self.getInstanceCountByMode()
                    distOffset = dataBlock.inputValue(instanceAlongCurveLocator.distOffsetAttr).asFloat()
                    curveLength = curveFn.length()

                    # Curve thresholds
                    curveStart = dataBlock.inputValue(instanceAlongCurveLocator.curveStartAttr).asFloat() * curveLength
                    curveEnd = dataBlock.inputValue(instanceAlongCurveLocator.curveEndAttr).asFloat() * curveLength

                    effectiveCurveLength = min(max(curveEnd - curveStart, 0.001), curveLength)
                    lengthIncrement = self.getIncrementByMode(instanceCount, effectiveCurveLength)

                    # Common data
                    inputTransformPlug = self.getInputTransformPlug()
                    inputTransformFn = self.getInputTransformFn()
                    
                    # Force update of transformation 
                    if OpenMaya.MPlug(self.thisMObject(), instanceAlongCurveLocator.inputTransformAttr).isConnected():
                        dataBlock.inputValue(inputTransformPlug).asMatrix()

                    # Manipulator data
                    curveAxisHandleArray = dataBlock.inputArrayValue(instanceAlongCurveLocator.curveAxisHandleAttr.compound)
                    axisHandlesSorted = getSortedCurveAxisArray(self.thisMObject(), curveAxisHandleArray, instanceCount)

                    if updateTranslation:
                        self.updateInstancePositions(curveFn, dataBlock, instanceCount, distOffset, curveStart, curveEnd, effectiveCurveLength, lengthIncrement, inputTransformPlug, inputTransformFn, axisHandlesSorted)

                    if updateRotation:
                        self.updateInstanceRotations(curveFn, dataBlock, instanceCount, distOffset, curveStart, curveEnd, effectiveCurveLength, lengthIncrement, inputTransformPlug, inputTransformFn, axisHandlesSorted)

                    if updateScale:
                        self.updateInstanceScale(curveFn, dataBlock, instanceCount, distOffset, curveStart, curveEnd, effectiveCurveLength, lengthIncrement)

        except:
            sys.stderr.write('Failed trying to compute locator. stack trace: \n')
            sys.stderr.write(traceback.format_exc())
            return OpenMaya.kUnknownParameter 
開發者ID:mmerchante,項目名稱:instanceAlongCurve,代碼行數:52,代碼來源:instanceAlongCurve.py


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