コード例 #1
0
    def TransformPosition(self, position, weightList, transformList, frames):
        outPositionList = []
        for f in range(0, frames):

            # transform the vertex for given frame
            p = rt.Point3(0, 0, 0)
            for w in range(0, len(weightList)):
                p += position * rt.inverse(transformList[w][0]) * transformList[w][f] * weightList[w]

            # and store them in outPositionList
            outPositionList.append(p)

        return outPositionList
コード例 #2
0
ファイル: Learner.py プロジェクト: xuxiao305/HelperBoneSystem
    def createLabelMatrix(self, bone):
        labelMatrix = []
        for f in range(0, self.option.MotionLearningframes):
            rt.sliderTime = f
            boneLocalXF = bone.Transform
            if bone.parent:
                boneLocalXF = boneLocalXF * rt.inverse(bone.parent.Transform)
            t = boneLocalXF.translation
            print t
            # r =  rt.quatToEuler2(bone.rotation)
            r = self.computeUtil.codeExpotentialMap(bone.rotation)

            # labelMatrix.append([t.x, t.y, t.z])
            labelMatrix.append([t.x, t.y, t.z, r.x, r.y, r.z])
        print 'createLabelMatrix'
        print labelMatrix
        return labelMatrix
コード例 #3
0
ファイル: Learner.py プロジェクト: xuxiao305/HelperBoneSystem
    def rot2Polynom(self, node):
        if node.parent:
            nodeLocalXF = node.Transform * rt.inverse(node.parent.Transform)
        else:
            nodeLocalXF = node.Transform
        # eulerRotation = rt.quatToEuler2(node.Transform.rotation)
        eulerRotation = rt.quatToEuler2(nodeLocalXF.rotation)
        # x = eulerRotation.x / 180.0
        # y = eulerRotation.y / 180.0
        # z = eulerRotation.z / 180.0

        eulerRotation = self.computeUtil.codeExpotentialMap(
            nodeLocalXF.rotation)

        x = eulerRotation.x
        y = eulerRotation.y
        z = eulerRotation.z
        # return [x, y, z, x*y, x*z, y*z, x*x, y*y, z*z, x*x*x, y*y*y, z*z*z, x*y*z, x*x*y,x*x*z,y*y*x,y*y*z,z*z*x,z*z*y]
        return [
            x, y, z, x * y, x * z, y * z, x * x, y * y, z * z
        ]  #, x*x*x, y*y*y, z*z*z, x*y*z, x*x*y,x*x*z,y*y*x,y*y*z,z*z*x,z*z*y]
コード例 #4
0
ファイル: Learner.py プロジェクト: xuxiao305/HelperBoneSystem
    def stepOneAxis(self,
                    step,
                    bnName,
                    boneXF,
                    a,
                    f,
                    vertIndexSet,
                    mode='translate'):
        boneNewXF = rt.Matrix3(boneXF[0], boneXF[1], boneXF[2], boneXF[3])

        if mode == 'translate':
            if a == 0:
                translationVector = rt.Point3(step, 0, 0)
            elif a == 1:
                translationVector = rt.Point3(0, step, 0)
            else:
                translationVector = rt.Point3(0, 0, step)
            boneNewXF = rt.translate(boneNewXF, translationVector)

        elif mode == 'rotate':
            if a == 0:
                rotMatrix = rt.rotateXMatrix(step)
            elif a == 1:
                rotMatrix = rt.rotateYMatrix(step)
            else:
                rotMatrix = rt.rotateZMatrix(step)

            # translate the matrix back to origin
            boneNewXFTranslation = boneNewXF.translation
            boneNewXF = rt.translate(boneNewXF, -boneNewXFTranslation)
            # make the rotation and translate it back
            boneNewXF = boneNewXF * rotMatrix
            boneNewXF = rt.translate(boneNewXF, boneNewXFTranslation)

        postSimError = 0

        simVertSetPos = []

        for v in vertIndexSet:
            preSimVertPos = self.regularMeshData.allVertPosList[v][f]

            weight = 0
            for vertBoneIndex in range(
                    0, len(self.regularMeshData.allVertBoneList[v])):
                if self.regularMeshData.allVertBoneList[v][
                        vertBoneIndex].Name == bnName:

                    weight = self.regularMeshData.allWeightList[v][
                        vertBoneIndex]

            simVertPos = preSimVertPos * (1 -
                                          weight) + preSimVertPos * rt.inverse(
                                              boneXF) * boneNewXF * weight

            simVertSetPos.append(simVertPos)

            referenceVertPos = self.referenceMeshData.allVertPosList[v][f]

            postSimError += self.computeUtil.computeErrorForOnePos(
                simVertPos, referenceVertPos)

        return boneNewXF, simVertSetPos, postSimError
コード例 #5
0
ファイル: fracture.py プロジェクト: ShirzadBh/tutorials
def execute():

    # Define the target object
    my_target = mxs.selection[0]

    # Reset the pivot
    my_target.pivot = my_target.center

    # Define the grid object
    my_grid = mxs.grid()

    # Define the vector
    vector = my_target.transform.position - mxs.inverse(
        mxs.viewport.getTM()).position

    # Define the length of the target
    distance = (mxs.length(my_target.min - my_target.max) / 2)

    # Normalize + UP vector (Z)
    X = mxs.normalize(vector)
    Z = mxs.point3(0, 0, 1)
    Y = mxs.normalize(mxs.cross(Z, X))
    Z = mxs.normalize(mxs.cross(X, Y))

    # Define a new transform based on vector
    my_transform = mxs.matrix3(Z, Y, X, my_target.transform.position)

    # Edit the position of the transform
    new_position = my_transform.position - (X * distance)
    my_transform = mxs.matrix3(Z, Y, X, new_position)

    # Assign the transform to the grid
    my_grid.transform = my_transform

    # Activate the grid
    mxs.activegrid = my_grid

    # Define spline method
    def setMode(name):
        name.curveType = 1

    try:
        # Set iso view
        mxs.execute("max vpt iso user")

        # Define user draw curves
        curves = mxs.startObjectCreation(mxs.FreehandSpline,
                                         returnNewNodes=True,
                                         newNodeCallback=setMode)

        # Define modifiers
        noise_mod = mxs.Noisemodifier()
        quad_mod = mxs.Quadify_Mesh()
        extrude_mod = mxs.Extrude()

        # Change the parameters
        extrude_mod.amount = distance * 2
        quad_mod.quadsize = 2
        noise_mod.scale = 10
        noise_mod.fractal = True
        noise_mod.strength = mxs.point3(2, 10, 2)

        # Add the modifiers
        mxs.addmodifier(curves, extrude_mod)
        mxs.addmodifier(curves, quad_mod)
        mxs.addmodifier(curves, noise_mod)

        # Define cutter splines
        mxs.ProCutter.CreateCutter(curves, 1, True, True, False, True, True)

        # Define stock object
        mxs.ProCutter.AddStocks(curves[0], my_target, 1, 1)

        # Set perspective view
        mxs.execute("max vpt persp user")

        # Deactivate and delete the grid
        mxs.activegrid = None
        mxs.delete(my_grid)

    except:

        # Set perspective view
        mxs.execute("max vpt persp user")

        # Deactivate and delete the grid
        mxs.activegrid = None
        mxs.delete(my_grid)

        print("cancled")
コード例 #6
0
    def applyTransform(self, position, weight, transform, restTransform):
        # transform the vertex for given weight
        p = position * rt.inverse(restTransform) * transform * weight

        return p