Esempio n. 1
0
    def __init__(self, name, solverTypeName, extension):
        super(KLOperator, self).__init__(name)

        self.solverTypeName = solverTypeName
        self.extension = extension

        # Load the Fabric Engine client and construct the RTVal for the Solver
        ks.loadCoreClient()
        ks.loadExtension('Kraken')
        if self.extension != 'Kraken':
            ks.loadExtension(self.extension)
        self.solverRTVal = ks.constructRTVal(self.solverTypeName)
        self.args = self.solverRTVal.getArguments('KrakenSolverArg[]')

        # Initialize the inputs and outputs based on the given args.
        for i in xrange(len(self.args)):
            arg = self.args[i]
            argName = arg.name.getSimpleType()
            argDataType = arg.dataType.getSimpleType()
            argConnectionType = arg.connectionType.getSimpleType()

            if argConnectionType == 'In':
                if argDataType.endswith('[]'):
                    self.inputs[argName] = []
                else:
                    self.inputs[argName] = None
            else:
                if argDataType.endswith('[]'):
                    self.outputs[argName] = []
                else:
                    self.outputs[argName] = None
Esempio n. 2
0
    def compute(self):
        """invokes the constraint and returns the resulting transform

        Returns:
            xfo: The result of the constraint in global space.

        """

        if self._constrainee is None:
            return None
        if len(self._constrainers) == 0:
            return None
        if self.getMaintainOffset():
            return self._constrainee.xfo

        cls = self.__class__.__name__
        ks.loadExtension('KrakenForCanvas')
        rtVal = ks.rtVal('Kraken%s' % cls)

        for c in self._constrainers:
            rtVal.addConstrainer('', ks.rtVal('Xfo', c.globalXfo).toMat44('Mat44'))

        # Using globalXfo here would cause a recursion
        return Xfo(rtVal.compute("Xfo",
                                 ks.rtVal('Xfo', self._constrainee.xfo).toMat44('Mat44')))
Esempio n. 3
0
    def computeOffset(self):
        """Invokes the constraint and computes the offset

        Returns:
            xfo: The offset to be used for the constraint.

        """

        if self._constrainee is None:
            return Xfo()
        if len(self._constrainers) == 0:
            return Xfo()
        if not self.getMaintainOffset():
            return Xfo()

        cls = self.__class__.__name__
        ks.loadExtension('KrakenForCanvas')
        rtVal = ks.rtVal('Kraken%s' % cls)

        rtVal.offset = ks.rtVal('Mat44', Mat44())
        for c in self._constrainers:
            rtVal.addConstrainer('', ks.rtVal('Xfo', c.globalXfo).toMat44('Mat44'))

        return Xfo(rtVal.computeOffset("Xfo",
                                       ks.rtVal('Xfo', self._constrainee.xfo).toMat44('Mat44')))
Esempio n. 4
0
    def computeOffset(self):
        """Invokes the constraint and computes the offset

        Returns:
            xfo: The offset to be used for the constraint.

        """

        if self._constrainee is None:
            return Xfo()
        if len(self._constrainers) == 0:
            return Xfo()
        if not self.getMaintainOffset():
            return Xfo()

        cls = self.__class__.__name__
        ks.loadExtension('KrakenForCanvas')
        rtVal = ks.rtVal('KrakenForCanvas::Kraken%s' % cls)

        rtVal.offset = ks.rtVal('Mat44', Mat44())
        for c in self._constrainers:
            rtVal.addConstrainer('',
                                 ks.rtVal('Xfo', c.globalXfo).toMat44('Mat44'))

        return Xfo(
            rtVal.computeOffset(
                "Xfo",
                ks.rtVal('Xfo', self._constrainee.xfo).toMat44('Mat44')))
Esempio n. 5
0
    def __init__(self, name, solverTypeName, extension, metaData=None):
        super(KLOperator, self).__init__(name, metaData=metaData)

        self.solverTypeName = solverTypeName
        self.extension = extension

        # Load the Fabric Engine client and construct the RTVal for the Solver
        ks.loadCoreClient()
        ks.loadExtension('Kraken')
        if self.extension != 'Kraken':
            ks.loadExtension(self.extension)
        self.solverRTVal = ks.constructRTVal(
            '%s::%s' % (self.extension, self.solverTypeName))

        # logger.debug("Creating kl operator object [%s] of type [%s] from extension [%s]:" % (self.getName(), self.solverTypeName, self.extension))

        self.args = self.solverRTVal.getArguments('Kraken::KrakenSolverArg[]')

        # Initialize the inputs and outputs based on the given args.
        for i in xrange(len(self.args)):
            arg = self.args[i]
            argName = arg.name.getSimpleType()
            argDataType = arg.dataType.getSimpleType()
            argConnectionType = arg.connectionType.getSimpleType()

            # Note, do not create empty arrays here as we need to know later whether or not
            # to create default values if input/output is None
            if argConnectionType == 'In':
                self.inputs[argName] = None
            else:
                self.outputs[argName] = None
Esempio n. 6
0
    def compute(self):
        """invokes the constraint and returns the resulting transform

        Returns:
            xfo: The result of the constraint in global space.

        """

        if self._constrainee is None:
            return None
        if len(self._constrainers) == 0:
            return None
        if self.getMaintainOffset():
            return self._constrainee.xfo

        cls = self.__class__.__name__
        ks.loadExtension('KrakenForCanvas')
        rtVal = ks.rtVal('KrakenForCanvas::Kraken%s' % cls)

        for c in self._constrainers:
            rtVal.addConstrainer('',
                                 ks.rtVal('Xfo', c.globalXfo).toMat44('Mat44'))

        # Using globalXfo here would cause a recursion
        return Xfo(
            rtVal.compute(
                "Xfo",
                ks.rtVal('Xfo', self._constrainee.xfo).toMat44('Mat44')))
Esempio n. 7
0
    def __init__(self, name, solverTypeName, extension, alwaysEval=False):
        super(SpliceOperator, self).__init__(name)

        self.solverTypeName = solverTypeName
        self.extension = extension
        self.alwaysEval = alwaysEval  # This is for Softimage only to force eval.

        # Load the Fabric Engine client and construct the RTVal for the Solver
        ks.loadCoreClient()
        ks.loadExtension('Kraken')
        if self.extension != 'Kraken':
            ks.loadExtension(self.extension)
        self.solverRTVal = ks.constructRTVal(self.solverTypeName)
        self.args = self.solverRTVal.getArguments('KrakenSolverArg[]')

        # Initialize the inputs and outputs based on the given args.
        for i in xrange(len(self.args)):
            arg = self.args[i]
            if arg.connectionType == 'in':
                if str(arg.dataType).endswith('[]'):
                    self.inputs[arg.name] = []
                else:
                    self.inputs[arg.name] = None
            else:
                if str(arg.dataType).endswith('[]'):
                    self.outputs[arg.name] = []
                else:
                    self.outputs[arg.name] = None
Esempio n. 8
0
    def __init__(self, name, solverTypeName, extension, alwaysEval=False):
        super(SpliceOperator, self).__init__(name)

        self.solverTypeName = solverTypeName
        self.extension = extension
        self.alwaysEval = alwaysEval # This is for Softimage only to force eval.

        # Load the Fabric Engine client and construct the RTVal for the Solver
        ks.loadCoreClient()
        ks.loadExtension('Kraken')
        if self.extension != 'Kraken':
            ks.loadExtension(self.extension)
        self.solverRTVal = ks.constructRTVal(self.solverTypeName)
        self.args = self.solverRTVal.getArguments('KrakenSolverArg[]')

        # Initialize the inputs and outputs based on the given args.
        for i in xrange(len(self.args)):
            arg = self.args[i]
            if arg.connectionType == 'in':
                if str(arg.dataType).endswith('[]'):
                    self.inputs[arg.name] = []
                else:
                    self.inputs[arg.name] = None
            else:
                if str(arg.dataType).endswith('[]'):
                    self.outputs[arg.name] = []
                else:
                    self.outputs[arg.name] = None
Esempio n. 9
0
    def __init__(self, name, solverTypeName, extension):
        super(KLOperator, self).__init__(name)

        self.solverTypeName = solverTypeName
        self.extension = extension

        # Load the Fabric Engine client and construct the RTVal for the Solver
        ks.loadCoreClient()
        ks.loadExtension('Kraken')
        if self.extension != 'Kraken':
            ks.loadExtension(self.extension)
        self.solverRTVal = ks.constructRTVal(self.solverTypeName)
        self.args = self.solverRTVal.getArguments('KrakenSolverArg[]')

        # Initialize the inputs and outputs based on the given args.
        for i in xrange(len(self.args)):
            arg = self.args[i]
            argName = arg.name.getSimpleType()
            argDataType = arg.dataType.getSimpleType()
            argConnectionType = arg.connectionType.getSimpleType()

            if argConnectionType == 'In':
                if argDataType.endswith('[]'):
                    self.inputs[argName] = []
                else:
                    self.inputs[argName] = None
            else:
                if argDataType.endswith('[]'):
                    self.outputs[argName] = []
                else:
                    self.outputs[argName] = None
Esempio n. 10
0
    def __init__(self):
        super(GraphManager, self).__init__()

        client = ks.getCoreClient()
        ks.loadExtension('KrakenForCanvas')

        self.__dfgHost = client.getDFGHost()
        self.__dfgBinding = self.__dfgHost.createBindingToNewGraph()
        self.__dfgExec = self.__dfgBinding.getExec()
        self.__dfgArgs = {}
        self.__dfgNodes = {}
        self.__dfgNodeAndPortMap = {}
        self.__dfgConnections = {}
        self.__dfgGroups = {}
        self.__dfgGroupNames = []
        self.__dfgCurrentGroup = None
Esempio n. 11
0
    def __init__(self):
        super(GraphManager, self).__init__()

        client = ks.getCoreClient()
        ks.loadExtension('KrakenForCanvas')

        self.__dfgHost = client.getDFGHost()
        self.__dfgBinding = self.__dfgHost.createBindingToNewGraph()
        self.__dfgExec = self.__dfgBinding.getExec()
        self.__dfgArgs = {}
        self.__dfgNodes = {}
        self.__dfgNodeAndPortMap = {}
        self.__dfgConnections = {}
        self.__dfgGroups = {}
        self.__dfgGroupNames = []
        self.__dfgCurrentGroup = None
Esempio n. 12
0
    def buildPoseConstraint(self, kConstraint):
        """Builds an pose constraint represented by the kConstraint.

        Args:
            kConstraint (object): kraken constraint object to build.

        Returns:
            bool: True if successful.

        """

        useXSIConstraint = True
        if useXSIConstraint:

            constraineeDCCSceneItem = self.getDCCSceneItem(
                kConstraint.getConstrainee())
            if kConstraint.getMaintainOffset():
                constraineeTransform = constraineeDCCSceneItem.Kinematics.Global.Transform

            constrainingObjs = getCollection()
            for eachConstrainer in kConstraint.getConstrainers():
                constrainer = self.getDCCSceneItem(eachConstrainer)

                if kConstraint.getMaintainOffset():
                    constrainerTransform = constrainer.Kinematics.Global.Transform

                # si.LogMessage( "%s,%s,%s" % (constrainer.posx.Value, constrainer.posy.Value, constrainer.posz.Value) )

                constrainingObjs.AddItems(constrainer)

            dccSceneItem = constraineeDCCSceneItem.Kinematics.AddConstraint(
                "Pose", constrainingObjs, kConstraint.getMaintainOffset())
            self._registerSceneItemPair(kConstraint, dccSceneItem)

        else:

            # Load the Fabric Engine client and construct the RTVal for the Solver
            ks.loadCoreClient()
            ks.loadExtension('Kraken')
            solverTypeName = 'PoseConstraintSolver'
            target = constraineeDCCSceneItem.FullName  # + ".kine.global"
            canvasOpPath = target + ".kine.global.CanvasOp"

            si.FabricCanvasOpApply(target, "", True, "", "")

            si.FabricCanvasAddPort(canvasOpPath, "", "solver", "In",
                                   solverTypeName, "Kraken")
            si.FabricCanvasAddPort(canvasOpPath, "", "debug", "In", "Boolean",
                                   "")
            si.FabricCanvasAddPort(canvasOpPath, "", "rightSide", "In",
                                   "Boolean", "")

            connectionTargets = ""
            connectionSuffix = ".kine.global"
            for eachConstrainer in kConstraint.getConstrainers():

                if eachConstrainer is None:
                    raise Exception("Constraint '" + kConstraint.getPath() +
                                    "' has invalid connection.")

                dccSceneItem = self.getDCCSceneItem(eachConstrainer)

                if dccSceneItem is None:
                    raise Exception(
                        "Constraint '" + kConstraint.getPath() +
                        "' of type '" + solverTypeName +
                        "' is connected to object without corresponding SceneItem:"
                        + eachConstrainer.getPath())

                connectionTargets = dccSceneItem.FullName + connectionSuffix
                break

            si.FabricCanvasAddPort(canvasOpPath, "", "constrainer", "In",
                                   "Mat44", "")
            # si.fabricSplice("addInputPort", canvasOpPath, "{\"portName\":\"constrainer\", \"dataType\":\"Mat44\", \"extension\":\"\", \"targets\":\"" + connectionTargets + "\"}", "")

            # Generate the operator source code.
            opSourceCode = ""
            opSourceCode += "require Kraken;\n"
            opSourceCode += "operator poseConstraint(\n"
            opSourceCode += "    io " + solverTypeName + " solver,\n"
            opSourceCode += "    in Boolean debug,\n"
            opSourceCode += "    in Boolean rightSide,\n"
            opSourceCode += "    io Mat44 constrainee,\n"
            opSourceCode += "    in Mat44 constrainer\n"
            opSourceCode += "    )\n"
            opSourceCode += "{\n"
            opSourceCode += "    solver.solve(debug, rightSide, constrainer, constrainee);"
            opSourceCode += "}\n"

            si.fabricSplice('addKLOperator', canvasOpPath,
                            '{"opName": "poseConstraint"}', opSourceCode)

        return dccSceneItem
Esempio n. 13
0
    def buildPoseConstraint(self, kConstraint):
        """Builds an pose constraint represented by the kConstraint.

        Args:
            kConstraint (object): kraken constraint object to build.

        Returns:
            bool: True if successful.

        """


        useXSIConstraint = True
        if useXSIConstraint:

            constraineeDCCSceneItem = self.getDCCSceneItem(kConstraint.getConstrainee())
            if kConstraint.getMaintainOffset():
                constraineeTransform = constraineeDCCSceneItem.Kinematics.Global.Transform

            constrainingObjs = getCollection()
            for eachConstrainer in kConstraint.getConstrainers():
                constrainer = self.getDCCSceneItem(eachConstrainer)

                if kConstraint.getMaintainOffset():
                    constrainerTransform = constrainer.Kinematics.Global.Transform

                # si.LogMessage( "%s,%s,%s" % (constrainer.posx.Value, constrainer.posy.Value, constrainer.posz.Value) )

                constrainingObjs.AddItems(constrainer)

            dccSceneItem = constraineeDCCSceneItem.Kinematics.AddConstraint("Pose", constrainingObjs, kConstraint.getMaintainOffset())
            self._registerSceneItemPair(kConstraint, dccSceneItem)

        else:

            # Load the Fabric Engine client and construct the RTVal for the Solver
            ks.loadCoreClient()
            ks.loadExtension('Kraken')
            solverTypeName = 'PoseConstraintSolver'
            target = constraineeDCCSceneItem.FullName# + ".kine.global"
            canvasOpPath = target + ".kine.global.CanvasOp"

            si.FabricCanvasOpApply(target, "", True, "", "")

            si.FabricCanvasAddPort(canvasOpPath, "", "solver", "In", solverTypeName, "Kraken")
            si.FabricCanvasAddPort(canvasOpPath, "", "debug", "In", "Boolean", "")
            si.FabricCanvasAddPort(canvasOpPath, "", "rightSide", "In", "Boolean", "")

            connectionTargets = ""
            connectionSuffix = ".kine.global"
            for eachConstrainer in kConstraint.getConstrainers():

                if eachConstrainer is None:
                    raise Exception("Constraint '"+kConstraint.getPath()+"' has invalid connection.");

                dccSceneItem = self.getDCCSceneItem(eachConstrainer)

                if dccSceneItem is None:
                    raise Exception("Constraint '"+kConstraint.getPath()+"' of type '"+solverTypeName+"' is connected to object without corresponding SceneItem:" + eachConstrainer.getPath());

                connectionTargets = dccSceneItem.FullName + connectionSuffix
                break

            si.FabricCanvasAddPort(canvasOpPath, "", "constrainer", "In", "Mat44", "")
            # si.fabricSplice("addInputPort", canvasOpPath, "{\"portName\":\"constrainer\", \"dataType\":\"Mat44\", \"extension\":\"\", \"targets\":\"" + connectionTargets + "\"}", "")

            # Generate the operator source code.
            opSourceCode = ""
            opSourceCode += "require Kraken;\n"
            opSourceCode += "operator poseConstraint(\n"
            opSourceCode += "    io " + solverTypeName + " solver,\n"
            opSourceCode += "    in Boolean debug,\n"
            opSourceCode += "    in Boolean rightSide,\n"
            opSourceCode += "    io Mat44 constrainee,\n"
            opSourceCode += "    in Mat44 constrainer\n"
            opSourceCode += "    )\n"
            opSourceCode += "{\n"
            opSourceCode += "    solver.solve(debug, rightSide, constrainer, constrainee);"
            opSourceCode += "}\n"

            si.fabricSplice('addKLOperator', canvasOpPath, '{"opName": "poseConstraint"}', opSourceCode)

        return dccSceneItem