Ejemplo n.º 1
0
def doesExist(node, location):
    producer = Nodes3DAPI.GetRenderProducer(node, 0, False, 0)
    geometryProc = producer.getProducerByPath(location)
    if geometryProc is not None:
        return True
    else:
        return False
Ejemplo n.º 2
0
    def nameChangedCallback(self, *args, **kwds):
        nameParameter = self.__node.getParameter('name')
        nm_node = SA.GetRefNode(self.__node, 'networkMaterial')
        nm_node.getParameter('name').setValue(nameParameter.getValue(0), 0)

        Producer = Nodes3DAPI.GetRenderProducer(self.__node, 0, False, 0)
        callback = []
        location = "/root/materials/materialx"
        proc = Producer.getProducerByPath(location)
        SA.WalkProducer(proc, callback, ["material"])
        new_location = ""
        for path in callback:
            if new_location:
                new_location = new_location + "|" + path
            else:
                # The first path
                new_location = path
        attr_node = SA.GetRefNode(self.__node, 'arnoldGlobalSettings')
        attr_node.getParameter('args.arnoldGlobalStatements.operators.enable').setValue(True, 0)
        param = attr_node.getParameter('args.arnoldGlobalStatements.operators.value')
        operators = param.getValue(0)
        for operator_path in operators.split("|"):
            # if operator_path under '/root/materials/materialx', skip!
            if operator_path.find(location) >= 0:
                continue
            if operator_path in callback:
                continue
            # if operator_path is "", skip!
            if operator_path == "":
                continue
            new_location = new_location + "|" + operator_path
        param.setValue(new_location, 0)
        return 1
Ejemplo n.º 3
0
def getRigScale(node, location):
    scale = [1.0, 1.0, 1.0]
    producer = Nodes3DAPI.GetRenderProducer(node, 0, False, 0)
    geometryproducer = producer.getProducerByPath(location)
    ad = geometryproducer.getAttribute('bound')
    if ad :
        data = ad.getData()
        scale = math.sqrt( math.pow((data[5]-data[4])/2, 2) + math.pow((data[1]-data[0])/2, 2) )
    return scale
Ejemplo n.º 4
0
def getRigTranslate(node, location):
    translate = [0.0, 0.0, 0.0]
    producer = Nodes3DAPI.GetRenderProducer(node, 0, False, 0)
    geometryproducer = producer.getProducerByPath(location)
    ad=geometryproducer.getDelimitedLocalAttribute('bound')
    if ad :
        data = ad.getData()
        translate = [(data[0]+data[1])/2, (data[2]+data[3])/2, (data[4]+data[5])/2]
    return translate
Ejemplo n.º 5
0
def importRigsSet(node):
    gaffer_three_node = getGafferThreeNode(node)
    root_locations = node.getParameter('rootLocations').getChildren()
    producer = Nodes3DAPI.GetRenderProducer(node, 0, False, 0)
    if not gaffer_three_node:
        message = "GafferThree node have not be connected to GafferThreeRigs!"
        setMessage(message)
        log.warning(message)
        return

    if not root_locations:
        message = "GafferThreeRigs node has no rootLocation!"
        setMessage(message)
        log.warning(message)
        return
    else:
        if root_locations and root_locations[0].getValue(0) is "":
            message = "GafferThreeRigs has no rootLocation"
            log.warning(message)
            return


    if not producer.getProducerByPath(getGafferThreeLocation(node) + "/" + cRigLayers[0]):
        chr_layer_rig_node = createRig(gaffer_three_node, cRigLayers[0])        
        setCharacterRig(gaffer_three_node, node, chr_layer_rig_node)
    else:
        chr_layer_rig_node = getRootRig(gaffer_three_node, cRigLayers[0])
        setCharacterRig(gaffer_three_node, node, chr_layer_rig_node)


    if not producer.getProducerByPath(getGafferThreeLocation(node) + "/" + cRigLayers[1]):
        env_layer_rig_node = createRig(gaffer_three_node, cRigLayers[1])
        setEnvrionmentRig(gaffer_three_node, node, env_layer_rig_node)
    else:
        message = "Light rig env_layer already created!"
        log.warning(message)

    if not producer.getProducerByPath(getGafferThreeLocation(node) + "/" + cRigLayers[2]):
        vol_layer_rig_node = createRig(gaffer_three_node, cRigLayers[2])
    else:
        message = "Light rig vol_layer already created!"
        log.warning(message)

    message = "Light rigs have been created into {%s} node!"%gaffer_three_node.getName()
    setMessage(message)
    CacheManager.flush(True)
Ejemplo n.º 6
0
def getCommonRigTranslate(node, locationNodes):
    rig_position_list = []
    for location in locationNodes:
        translate = [0.0, 0.0, 0.0]
        location_value = location.getValue(0)
        producer = Nodes3DAPI.GetRenderProducer(node, 0, False, 0)
        geometryproducer = producer.getProducerByPath(location_value)
        ad = geometryproducer.getDelimitedLocalAttribute('bound')
        if ad :
            data = ad.getData()
            translate = [(data[0]+data[1])/2, (data[2]+data[3])/2, (data[4]+data[5])/2]
        rig_position_list.append(translate)
    center_x = center_y = center_z = 0
    for position in rig_position_list:
        center_x += position[0]
        center_y += position[1]
        center_z += position[2]
    length = len(rig_position_list)
    return (center_x/length, center_y/length, center_z/length)
Ejemplo n.º 7
0
    def rootLocationsParameterChangedCallback(self, *args, **kwds):
        root_locations = self.__node.getParameter('rootLocations')
        groupStackNode = SA.GetRefNode(self.__node, 'groupStack')
        opScriptNode = SA.GetRefNode(self.__node, 'opScript')
        location_list = []
        for location in root_locations.getChildren():
            location_value = location.getValue(0)           
            if location_value is not "":
                location_list.append(location_value)

        for child in groupStackNode.getChildNodes():
            groupStackNode.deleteChildNode(child)

        cel_string = ""
        Producer = Nodes3DAPI.GetRenderProducer(self.__node, 0, False, 0)
        for location in location_list:
            cel_string = cel_string + " " + location
            gnode = groupStackNode.buildChildNode(adoptNode=None)
            gnode.getParameter("paths.i0").setValue(location, 0)
            gnode.getParameter("attributeName").setValue("LightChaserAnimation.lightRig.assetName",0)
            gnode.getParameter("attributeType").setValue("string",0)
            gnode.getParameter('stringValue.i0').setValue(location,0)

        opScriptNode.getParameter('CEL').setValue(cel_string, 0)
Ejemplo n.º 8
0
    def rootLocationsParameterChangedCallback(self, *args, **kwds):
        root_locations = self.__node.getParameter('rootLocations')
        groupStackNode = SA.GetRefNode(self.__node, 'groupStack')
        opScriptNode = SA.GetRefNode(self.__node, 'opScript')
        location_list = []
        for location in root_locations.getChildren():
            location_value = location.getValue(0)
            if location_value is not "":
                location_list.append(location_value)

        for child in groupStackNode.getChildNodes():
            groupStackNode.deleteChildNode(child)

        cel_string = ""
        Producer = Nodes3DAPI.GetRenderProducer(self.__node, 0, False, 0)
        for location in location_list:
            cel_string = cel_string + " " + location
            proc = Producer.getProducerByPath(location)
            ad = proc.getDelimitedLocalAttribute('bound')
            if ad is not None:
                continue
            callback = []
            SA.WalkProducer(proc, callback, ["subdmesh", "polymesh"])
            bodygeo_string = "/root/world/geo"
            for path in callback:
                if path[-13:] == "body_geoShape":
                    bodygeo_string = path
            gnode = groupStackNode.buildChildNode(adoptNode=None)
            gnode.getParameter("paths.i0").setValue(location, 0)
            gnode.getParameter("attributeName").setValue(
                "LightChaserAnimation.assembly.bodyGeometry", 0)
            gnode.getParameter("attributeType").setValue("string", 0)
            gnode.getParameter('stringValue.i0').setValue(bodygeo_string, 0)

        opScriptNode.getParameter('CEL').setValue(cel_string, 0)
        return 1
Ejemplo n.º 9
0
    def bake(self):
        import KTMaterialXTools.ScriptMaterialX as MateX
        reload(MateX)
        switch_node = SA.GetRefNode(self, 'switch')
        merge_node = SA.GetRefNode(self, 'merge')
        def walkProducer(producer, callback, location_types=[]):
           child = producer.getFirstChild()
           while child:
               walkProducer(child, callback, location_types)
               child = child.getNextSibling()
           if producer.getType() in location_types:
               fullLocation = producer.getFullName()
               callback.append(fullLocation)
        def makeCollctions(producer, callback, collations):
            for path in callback:
                proc = producer.getProducerByPath(path)
                attr=proc.getAttribute("geometry.arbitrary.materialAssigned.value")
                temp_map = {}
                temp_map["material"] = attr.getValue()
                temp_map["collction"] = path
                collations.append(temp_map)


        # Get attribute rootLocations.
        rootLocationsParameters = self.getParameter('rootLocations').getChildren()
        rootLocations = []
        for rootLocationsParameter in rootLocationsParameters:
            rootLocations.append(rootLocationsParameter.getValue(0))
        rootLocations = sorted(rootLocations , key = len)


        # Get attribute saveTo.
        saveToParameter = self.getParameter('saveTo')
        saveTo = saveToParameter.getValue(0)

        # If saveTo is None, stop at first time here
        if not saveTo:
            log.warning("Parameter saveTo is empty, please enter the specify path!")
            return 


        children = self.getParameter('passes').getChildren()
        look_set = {}
        for child in children:
            look_name = child.getValue(0)

            index = switch_node.getInputPort(child.getName()).getIndex()
            switch_node.getParameter('in').setValue(index, 0)
            producer = Nodes3DAPI.GetRenderProducer(merge_node, 0, False, 0)

            callback = []
            collations = []
            location_types = ["subdmesh", "polymesh", "renderer procedural"]
            walkProducer(producer, callback, location_types)
            makeCollctions(producer, callback, collations)
            assignment_set = []
            for MC in collations:
                material_name = MC["material"]
                collation_path = MC["collction"]
                collation_name = collation_path
                for prefix in rootLocations:
                    if collation_path.startswith(prefix):
                        collation_name = collation_path[len(prefix):]
                assignment_set.append( (collation_name, material_name) )

            if assignment_set:
                look_set[look_name] = assignment_set

        MateX.export(look_set,saveTo)
        log.info("MaterialX file save to %s"%saveTo)
        # Set Switch back
        switch_node.getParameter('in').setValue(0, 0)
Ejemplo n.º 10
0
def getRootProducer(t='geometry'):
    # type='geometry' or 'render'
    if t == 'geometry':
        return Nodes3DAPI.GetGeometryProducer()
    return Nodes3DAPI.GetRenderProducer()
Ejemplo n.º 11
0
def updateParameters(node):
    def copyParam(param, params_list):
        param_name = param.getName()
        param_enable = param.getChild("enable")
        for p in params_list:
            if p.getName() == param_name and param_enable is not None:
                master_param_enable = p.getChild("enable").getValue(0)
                input_param_enable = param.getChild("enable").getValue(0)
                if master_param_enable and not input_param_enable:
                    children = p.getChild("value").getChildren()
                    if children is None:
                        value = p.getChild("value").getValue(0)
                        param.getChild("enable").setValue(1.0, 0)
                        param.getChild("value").setValue(value, 0)
                    else:
                        for child in children:
                            name = child.getName()
                            value = child.getValue(0)
                            param.getChild("enable").setValue(1.0, 0)
                            param_child = param.getChild("value").getChild(name)
                            if param_child is not None:
                                param_child.setValue(value, 0)

    gaffer_three_node = getGafferThreeNode(node)
    root_locations = node.getParameter('rootLocations').getChildren()
    producer = Nodes3DAPI.GetRenderProducer(node, 0, False, 0)
    if not gaffer_three_node:
        message = "GafferThree node have not be connected to GafferThreeRigs!"
        setMessage(message)
        log.warning(message)
        return

    if not root_locations:
        message = "GafferThreeRigs node has no rootLocation!"
        setMessage(message)
        log.warning(message)
        return
    else:
        if root_locations and root_locations[0].getValue(0) is "":
            message = "GafferThreeRigs has no rootLocation"
            log.warning(message)
            return

    master_chr_name = root_locations[0].getValue(0).split("/")[-1]
    chr_layer_rig_node = getRootRig(gaffer_three_node, cRigLayers[0])
    master_chr_rig = None
    rest_rig_set = []
    for chr_rig in chr_layer_rig_node.getChildren():
        if chr_rig.getType() != "Group":
            continue
        location = chr_rig.getParameter('__gaffer.location').getValue(0)
        current_chr_name = location.split("/")[-1]
        if current_chr_name == master_chr_name:
            master_chr_rig = chr_rig
        elif current_chr_name == "common":
            pass
        else:
            rest_rig_set.append(chr_rig)

    master_params_map = {}
    for light_group in master_chr_rig.getChildren():
        material_node_param = light_group.getParameter('node_material')
        location = light_group.getParameter('__gaffer.location')
        if material_node_param is not None:
            light_name = location.getValue(0).split("/")[-1]
            material_node_name = material_node_param.getValue(0)
            material_node = NodegraphAPI.GetNode(material_node_name)
            params_list = material_node.getParameter\
                ('shaders.arnoldLightParams').getChildren()
            master_params_map[light_name] = params_list

    for rig in rest_rig_set:
        for light_group in rig.getChildren():
            material_node_param = light_group.getParameter('node_material')
            location = light_group.getParameter('__gaffer.location')
            if material_node_param is not None:
                light_name = location.getValue(0).split("/")[-1]
                material_node_name = material_node_param.getValue(0)
                material_node = NodegraphAPI.GetNode(material_node_name)
                params_list = material_node.getParameter\
                    ('shaders.arnoldLightParams').getChildren()
                for param in params_list:
                    param_enable = param.getChild("enable")
                    if param_enable is not None:
                        # if this material param is not enable, we copy master 
                        # params to here and set it enable.
                        if light_name in master_params_map:
                            master_params_list = master_params_map[light_name]
                            copyParam(param, master_params_list)
    message = "Parameters in {%s} node have been updated!"%gaffer_three_node.getName()

    setMessage(message)