Example #1
0
    def create_cache(self, selection=True):
        register_time_callback()
        if self.cacheoptions.verbose is True:
            add_to_time_callback(time_verbose)

        start_frame, end_frame = self.cacheoptions.range
        workspace = self.workspace_widget.directory
        if workspace is None:
            return cmds.warning("no workspace set")
        set_last_used_workspace(workspace)
        self.workspace_widget.populate()

        if selection is True:
            nodes = self.nodetable.selected_nodes or []
        else:
            nodes = cmds.ls(type=DYNAMIC_NODES)
            nodes = filter_invisible_nodes_for_manager(nodes)

        create_and_record_cacheversion(
            workspace=workspace,
            start_frame=start_frame,
            end_frame=end_frame,
            nodes=nodes,
            behavior=self.cacheoptions.behavior,
            evaluate_every_frame=self.cacheoptions.samples_evaluated,
            save_every_evaluation=self.cacheoptions.samples_recorded,
            playblast=self.playblast.record_playblast,
            playblast_viewport_options=self.playblast.viewport_options)

        self.nodetable.set_workspace(workspace)
        self.nodetable.update_layout()
        self.selection_changed()
        unregister_time_callback()
        clear_time_callback_functions()
Example #2
0
    def selection_changed(self):
        nodes = self.nodetable.selected_nodes
        if not self.nodetable.selected_nodes:
            self.versions.set_nodes_and_cacheversions(None, None)
            self.comparison.set_node_and_cacheversion(None, None)
            return
        workspace = self.workspace_widget.workspace
        all_cacheversions = list_available_cacheversions(workspace)
        available_cacheversions = filter_cacheversions_containing_nodes(
            filter_invisible_nodes_for_manager(cmds.ls(type=DYNAMIC_NODES)),
            all_cacheversions)

        connected_cacheversions = filter_connected_cacheversions(
            nodes, available_cacheversions)
        if not connected_cacheversions:
            self.comparison.set_node_and_cacheversion(None, None)
            self.versions.set_nodes_and_cacheversions(nodes,
                                                      available_cacheversions)
            return

        self.versions.set_nodes_and_cacheversions(nodes,
                                                  available_cacheversions)
        if not cacheversion_contains_node(nodes[0],
                                          connected_cacheversions[0]):
            self.comparison.set_node_and_cacheversion(None, None)
            return
        self.comparison.set_node_and_cacheversion(nodes[0],
                                                  connected_cacheversions[0])
Example #3
0
def list_connected_cacheblends(nodes=None):
    '''
    :nodes: one or list of dyna,ic nodes as string ('hairSystem' and 'nCloth')
    '''
    nodes = nodes or filter_invisible_nodes_for_manager(cmds.ls(DYNAMIC_NODES))
    if not nodes:
        return []
    blendnodes = cmds.listConnections(nodes, type='cacheBlend')
    if blendnodes:
        return list(set(blendnodes))
Example #4
0
def append_ncache(nodes=None,
                  evaluate_every_frame=1.0,
                  save_every_evaluation=1):
    nodes = nodes or cmds.ls(DYNAMIC_NODES)
    nodes = filter_invisible_nodes_for_manager(nodes)
    cmds.cacheFile(refresh=True,
                   noBackup=True,
                   simulationRate=evaluate_every_frame,
                   sampleMultiplier=save_every_evaluation,
                   cacheableNode=nodes,
                   startTime=cmds.currentTime(query=True),
                   endTime=cmds.playbackOptions(max=True, query=True))
Example #5
0
def connect_cacheversion(cacheversion, nodes=None, behavior=0):
    nodes = nodes or cmds.ls(type=DYNAMIC_NODES)
    nodes = filter_invisible_nodes_for_manager(nodes)
    for node in nodes:
        if not cacheversion_contains_node(node, cacheversion):
            continue
        xml_file = find_file_match(node, cacheversion, extension='xml')
        if not xml_file:
            cmds.warning("no cache to connect for {}".format(xml_file))
            continue
        cachefile = import_ncache(node, xml_file, behavior=behavior)
        cmds.rename(cachefile, cacheversion.name + CACHENODENAME_SUFFIX)
Example #6
0
def create_and_record_cacheversion(workspace,
                                   start_frame,
                                   end_frame,
                                   comment=None,
                                   name=None,
                                   nodes=None,
                                   behavior=0,
                                   evaluate_every_frame=1.0,
                                   save_every_evaluation=1,
                                   playblast=False,
                                   playblast_viewport_options=None):

    cloth_nodes = cmds.ls(nodes, type="nCloth")

    nodes = nodes or cmds.ls(type=DYNAMIC_NODES)
    nodes = filter_invisible_nodes_for_manager(nodes)
    workspace = ensure_workspace_folder_exists(workspace)
    cacheversion = create_cacheversion(workspace=workspace,
                                       name=name,
                                       comment=comment,
                                       nodes=nodes,
                                       start_frame=start_frame,
                                       end_frame=end_frame,
                                       timespent=None)

    if playblast is True:
        start_playblast_record(directory=cacheversion.directory,
                               **playblast_viewport_options)
    save_pervertex_maps(nodes=cloth_nodes, directory=cacheversion.directory)
    start_time = datetime.now()
    record_ncache(nodes=nodes,
                  start_frame=start_frame,
                  end_frame=end_frame,
                  output=cacheversion.directory,
                  behavior=behavior,
                  evaluate_every_frame=evaluate_every_frame,
                  save_every_evaluation=save_every_evaluation)
    end_time = datetime.now()
    timespent = (end_time - start_time).total_seconds()
    time = cmds.currentTime(query=True)
    cacheversion.set_range(nodes, start_frame=start_frame, end_frame=time)
    cacheversion.set_timespent(nodes=nodes, seconds=timespent)

    if playblast is True:
        temp_path = stop_playblast_record(cacheversion.directory)
        move_playblast_to_cacheversion(temp_path, cacheversion)
    return cacheversion
Example #7
0
def record_ncache(nodes=None,
                  start_frame=0,
                  end_frame=100,
                  output=None,
                  behavior=0,
                  evaluate_every_frame=1.0,
                  save_every_evaluation=1):
    '''
    this function is a wrap around the mel command doCreateNclothCache
    it force an cache with one cache per geometry (containing all frame).
    :nodes: one or list of dynamic nodes as string ('hairSystem' and 'nCloth')
    :output: output folder (without filename)
    :behavior: as int
        0: replace all old connected cachenodes and blendnodes
        1: replace all old connected cachenodes but add new cache in blendnodes
        2: blend all existing cachenodes with new cache
    :evaluate: eveluate every frames
    :evaluation: record every samples
    '''
    nodes = nodes or cmds.ls(DYNAMIC_NODES)
    nodes = filter_invisible_nodes_for_manager(nodes)
    output = output or ''

    if behavior == 0:
        cmds.delete(list_connected_cachefiles(nodes))
        cmds.delete(list_connected_cacheblends(nodes))
    elif behavior == 1:
        cmds.delete(list_connected_cachefiles(nodes))
        connections = disconnect_cachenodes(nodes)
    elif behavior == 2:
        connections = disconnect_cachenodes(nodes)

    cmds.select(nodes)
    command = CACHE_COMMAND_TEMPLATE.format(
        start_frame=start_frame,
        end_frame=end_frame,
        output=output,
        evaluate_every_frame=evaluate_every_frame,
        save_every_evaluation=save_every_evaluation)
    cache_nodes = mel.eval(command)

    if behavior:
        reconnect_cachenodes(connections)
    return cache_nodes
Example #8
0
    def append_cache(self, selection=True):
        register_time_callback()
        if self.cacheoptions.verbose is True:
            add_to_time_callback(time_verbose)

        workspace = self.workspace_widget.directory
        if workspace is None:
            return cmds.warning("no workspace set")
        set_last_used_workspace(workspace)
        self.workspace_widget.populate()

        if selection is True:
            nodes = self.nodetable.selected_nodes or []
        else:
            nodes = cmds.ls(type=DYNAMIC_NODES)
            nodes = filter_invisible_nodes_for_manager(nodes)
        if not nodes:
            return cmds.warning("no nodes selected")

        cacheversion = None
        for node in nodes:
            cacheversions = filter_connected_cacheversions(
                [node], list_available_cacheversions(workspace))
            if not cacheversions:
                message = "some nodes doesn't have cache connected to append"
                return cmds.warning(message)
            if cacheversion is None:
                cacheversion = cacheversions[0]
            if cacheversions[0] != cacheversion:
                message = "append cache on multiple version is not suppported."
                return cmds.warning(message)

        append_to_cacheversion(
            nodes=nodes,
            cacheversion=cacheversion,
            evaluate_every_frame=self.cacheoptions.samples_evaluated,
            save_every_evaluation=self.cacheoptions.samples_recorded,
            playblast=self.playblast.record_playblast,
            playblast_viewport_options=self.playblast.viewport_options)
        self.nodetable.update_layout()
        self.selection_changed()
        unregister_time_callback()
        clear_time_callback_functions()
Example #9
0
    def erase_cache(self, selection=True):
        register_time_callback()
        if self.cacheoptions.verbose is True:
            add_to_time_callback(time_verbose)

        start_frame, end_frame = self.cacheoptions.range
        workspace = self.workspace_widget.directory
        if workspace is None:
            return cmds.warning("no workspace set")
        set_last_used_workspace(workspace)
        self.workspace_widget.populate()

        if selection is True:
            nodes = self.nodetable.selected_nodes or []
        else:
            nodes = cmds.ls(type=DYNAMIC_NODES)
            nodes = filter_invisible_nodes_for_manager(nodes)
        cacheversions = filter_connected_cacheversions(
            nodes, list_available_cacheversions(workspace))

        if not cacheversions or len(cacheversions) > 1:
            cmds.warning(
                'no valid cache version or more than one cacheversion are '
                'connected to the selected dynamic nodes')
            self.create_cache(selection=selection)
            return

        record_in_existing_cacheversion(
            cacheversion=cacheversions[0],
            start_frame=start_frame,
            end_frame=end_frame,
            nodes=nodes,
            behavior=self.cacheoptions.behavior,
            evaluate_every_frame=self.cacheoptions.samples_evaluated,
            save_every_evaluation=self.cacheoptions.samples_recorded,
            playblast=self.playblast.record_playblast,
            playblast_viewport_options=self.playblast.viewport_options)
        self.nodetable.update_layout()
        self.selection_changed()
        unregister_time_callback()
        clear_time_callback_functions()
Example #10
0
def append_to_cacheversion(cacheversion,
                           nodes=None,
                           evaluate_every_frame=1.0,
                           save_every_evaluation=1,
                           playblast=False,
                           playblast_viewport_options=None):

    if playblast is True:
        start_playblast_record(directory=cacheversion.directory,
                               **playblast_viewport_options)

    nodes = nodes or cmds.ls(type=DYNAMIC_NODES)
    nodes = filter_invisible_nodes_for_manager(nodes)
    start_time = datetime.now()
    append_ncache(nodes=nodes,
                  evaluate_every_frame=evaluate_every_frame,
                  save_every_evaluation=save_every_evaluation)
    end_time = datetime.now()
    # Add up the second spent for the append cache to the cache time spent
    # already recorded.
    timespent = (end_time - start_time).total_seconds()
    for node in cacheversion.infos.get('nodes'):
        if node not in nodes:
            continue
        seconds = cacheversion.infos.get(
            'nodes')[node]["timespent"] + timespent
        cacheversion.set_timespent(nodes=[node], seconds=seconds)
    cacheversion.update_modification_time()
    # Update the cached range in the cache info if the append cache
    # finished further the original cache
    time = cmds.currentTime(query=True)
    end_frame = cacheversion.infos.get('nodes')[node]['range'][1]
    if time > end_frame:
        cacheversion.set_range(nodes=nodes, end_frame=time)

    if playblast is True:
        temp_path = stop_playblast_record(cacheversion.directory)
        move_playblast_to_cacheversion(temp_path, cacheversion)
Example #11
0
    def send_wedging_cache(self, selection=False):
        if self.workspace is None:
            return cmds.warning("invalid workspace set")
        set_last_used_workspace(self.workspace)

        mayapy = cmds.optionVar(query=MAYAPY_PATH_OPTIONVAR)
        if os.path.exists(mayapy) is False:
            return cmds.warning("invalid mayapy path set")
        if selection is True:
            nodes = self.nodetable.selected_nodes or []
        else:
            nodes = cmds.ls(type=DYNAMIC_NODES)
            nodes = filter_invisible_nodes_for_manager(nodes)
        if not nodes:
            return cmds.warning("no nodes selected")

        start_frame, end_frame = self.cacheoptions.range
        cacheversions, processes = send_wedging_ncaches_jobs(
            workspace=self.workspace,
            name=self.batchcacher.wedging_name,
            start_frame=start_frame,
            end_frame=end_frame,
            nodes=nodes,
            evaluate_every_frame=self.cacheoptions.samples_evaluated,
            save_every_evaluation=self.cacheoptions.samples_recorded,
            playblast_viewport_options=self.playblast.viewport_options,
            timelimit=self.batchcacher.options.timelimit,
            stretchmax=self.batchcacher.options.explosion_detection_tolerance,
            attribute=self.batchcacher.attribute,
            values=self.batchcacher.wedging_values)
        self.processes.extend(processes)
        for cacheversion, process in zip(cacheversions, processes):
            self.batch_monitor.add_job(cacheversion, process)
        self.batch_monitor.show()
        self.nodetable.set_workspace(self.workspace)
        self.nodetable.update_layout()
        self.selection_changed()
Example #12
0
def record_in_existing_cacheversion(cacheversion,
                                    start_frame,
                                    end_frame,
                                    nodes=None,
                                    behavior=0,
                                    evaluate_every_frame=1.0,
                                    save_every_evaluation=1,
                                    playblast=False,
                                    playblast_viewport_options=None):

    if playblast is True:
        start_playblast_record(directory=cacheversion.directory,
                               **playblast_viewport_options)

    cloth_nodes = cmds.ls(nodes, type="nCloth")
    nodes = nodes or cmds.ls(type=DYNAMIC_NODES)
    nodes = filter_invisible_nodes_for_manager(nodes)
    save_pervertex_maps(nodes=cloth_nodes, directory=cacheversion.directory)
    start_time = datetime.now()
    record_ncache(nodes=nodes,
                  start_frame=start_frame,
                  end_frame=end_frame,
                  output=cacheversion.directory,
                  behavior=behavior,
                  evaluate_every_frame=evaluate_every_frame,
                  save_every_evaluation=save_every_evaluation)
    end_time = datetime.now()
    timespent = (end_time - start_time).total_seconds()
    time = cmds.currentTime(query=True)
    cacheversion.set_range(nodes, start_frame=start_frame, end_frame=time)
    cacheversion.set_timespent(nodes=nodes, seconds=timespent)
    cacheversion.update_modification_time()

    if playblast is True:
        temp_path = stop_playblast_record(cacheversion.directory)
        move_playblast_to_cacheversion(temp_path, cacheversion)