Пример #1
0
    def _registerOperations(self):
        """Register operations that should be run by the manager."""
        import hou

        # Look for files containing a list of operations.
        try:
            files = hou.findFiles("pyfilter/operations.json")

        # If no files could be found then abort.
        except hou.OperationFailed:
            return

        for filepath in files:
            with open(filepath) as fp:
                data = json.load(fp)

            if "operations" not in data:
                continue

            for operation in data["operations"]:
                module_name, class_name = operation

                # Import the operation class.
                cls = getattr(__import__(module_name, {}, {}, [class_name]),
                              class_name)

                logger.debug("Registering {}".format(class_name))

                # Add an instance of it to our operations list.
                self.operations.append(cls(self))
Пример #2
0
    def loadFromFile(self, filepath):
        """Load properties from a file."""
        logger.debug("Reading properties from {}".format(filepath))

        # Load json data from the file.
        with open(filepath) as f:
            data = json.load(f, object_hook=ht.utils.convertFromUnicode)

        self._loadFromData(data)
Пример #3
0
    def loadFromFile(self, filepath):
        """Load properties from a file."""
        logger.debug("Reading properties from {}".format(filepath))

        # Load json data from the file.
        with open(filepath) as f:
            data = json.load(f)

        self._loadFromData(data)
Пример #4
0
def filterCameraSegment():
    """Modify properties for a camera motion segment.

    Called just prior to the ray_end statement locking the settings for a
    camera motion segment.

    """
    logger.debug("filterCameraSegment")

    PYFILTER_MANAGER.runFilters("filterCameraSegment")
Пример #5
0
def filterOutputAssets(assets):
    """Filter assets generated by Mantra.

    Called after the render completes, and is passed a list of assets generated
    during the render.

    """
    logger.debug("filterOutputAssets")

    PYFILTER_MANAGER.runFilters("filterOutputAssets")
Пример #6
0
def filterFog():
    """Modify fog related properties.

    Called just prior to the ray_end statement which locks off the settings for
    a fog object. The function can query fog: settings and possibly alter them.

    """
    logger.debug("filterFog ({})".format(mantra.property("object:name")[0]))

    PYFILTER_MANAGER.runFilters("filterFog")
Пример #7
0
def filterFog():
    """Modify fog related properties.

    Called just prior to the ray_end statement which locks off the settings for
    a fog object. The function can query fog: settings and possibly alter them.

    """
    logger.debug("filterFog ({})".format(mantra.property("object:name")[0]))

    PYFILTER_MANAGER.runFilters("filterFog")
Пример #8
0
def filterCameraSegment():
    """Modify properties for a camera motion segment.

    Called just prior to the ray_end statement locking the settings for a
    camera motion segment.

    """
    logger.debug("filterCameraSegment")

    PYFILTER_MANAGER.runFilters("filterCameraSegment")
Пример #9
0
def filterOutputAssets(assets):
    """Filter assets generated by Mantra.

    Called after the render completes, and is passed a list of assets generated
    during the render.

    """
    logger.debug("filterOutputAssets")

    PYFILTER_MANAGER.runFilters("filterOutputAssets")
Пример #10
0
def filterMaterial():
    """Modify material related properties.

    Mantra has material blocks which can be applied on a per-primitive basis.
    This function is called before a material is locked off. The function can
    add or change properties on the material.

    """
    logger.debug("filterMaterial")

    PYFILTER_MANAGER.runFilters("filterMaterial")
Пример #11
0
def filterMaterial():
    """Modify material related properties.

    Mantra has material blocks which can be applied on a per-primitive basis.
    This function is called before a material is locked off. The function can
    add or change properties on the material.

    """
    logger.debug("filterMaterial")

    PYFILTER_MANAGER.runFilters("filterMaterial")
Пример #12
0
def filterGeometry():
    """Modify geometry related properties.

    Called just prior to the ray_end statement which locks off a geometry
    object. This allows the program to query geometry: settings and possibly
    alter them.

    """
    logger.debug("filterGeometry")

    PYFILTER_MANAGER.runFilters("filterGeometry")
Пример #13
0
def filterRender():
    """Query render related properties.

    Called just before the ray_raytrace command.  It's not possible to change
    any properties at this time in the IFD processing.  However, for
    statistics or validation, it might be useful to have this method available.

    """
    logger.debug("filterRender")

    PYFILTER_MANAGER.runFilters("filterRender")
Пример #14
0
def filterPlane():
    """Change query and modify image plane properties."""
    variable = mantra.property("plane:variable")[0]
    channel = mantra.property("plane:channel")[0]

    if variable == channel or channel == "":
        logger.debug("filterPlane ({})".format(variable))
    else:
        logger.debug("filterPlane ({} -> {})".format(variable, channel))

    PYFILTER_MANAGER.runFilters("filterPlane")
Пример #15
0
def filterRender():
    """Query render related properties.

    Called just before the ray_raytrace command.  It's not possible to change
    any properties at this time in the IFD processing.  However, for
    statistics or validation, it might be useful to have this method available.

    """
    logger.debug("filterRender")

    PYFILTER_MANAGER.runFilters("filterRender")
Пример #16
0
def filterPlane():
    """Change query and modify image plane properties."""
    variable = mantra.property("plane:variable")[0]
    channel = mantra.property("plane:channel")[0]

    if variable == channel or channel == "":
        logger.debug("filterPlane ({})".format(variable))
    else:
        logger.debug("filterPlane ({} -> {})".format(variable, channel))

    PYFILTER_MANAGER.runFilters("filterPlane")
Пример #17
0
def filterGeometry():
    """Modify geometry related properties.

    Called just prior to the ray_end statement which locks off a geometry
    object. This allows the program to query geometry: settings and possibly
    alter them.

    """
    logger.debug("filterGeometry")

    PYFILTER_MANAGER.runFilters("filterGeometry")
Пример #18
0
    def _loadFromData(self, data):
        """Build PropertySetter objects from data."""
        # Process each filter stage name and it's data.
        for stage_name, stage_data in data.iteritems():
            # A list of properties for this stage.
            properties = self.properties.setdefault(stage_name, [])

            # Check if the stage should be disabled.
            if "disabled" in stage_data:
                if stage_data["disabled"]:
                    logger.debug(
                        "Stage entry disabled: {}".format(stage_name)
                    )

                    continue

                # If not, remove the disabled entry.
                del(stage_data["disabled"])

            # The data is stored by property name.
            for property_name, property_block in stage_data.iteritems():

                # Wrapping properties in a 'rendertype:type' block is supported
                # if the the name indicates that we have to modify the data.
                if property_name.startswith("rendertype:"):
                    # Get the rendertype name.
                    rendertype = property_name.split(":")[1]

                    # Process each child property block.
                    for name, block in property_block.iteritems():
                        # If the child data is the standard dictionary of data
                        # we can just insert the rendertype value into it.
                        if isinstance(block, dict):
                            block["rendertype"] = rendertype

                        # If the child data is a list of dictionaries then
                        # iterate over each one and insert the value.
                        elif isinstance(block, list):
                            for item in block:
                                item["rendertype"] = rendertype

                        # Process the child data block.
                        self._processBlock(
                            properties, stage_name, name, block
                        )

                # Normal data.
                else:
                    self._processBlock(
                        properties, stage_name, property_name, property_block
                    )
Пример #19
0
def filterCamera():
    """Modify image related properties.

    Called just before the global properties are locked off for the render.
    This is usually prior to the declaration of any objects in the IFD.  If you
    change global properties after this, they probably will have no effect.

    Since mantra calls this function before any lights or instances are
    declared, you can set default light or instance properties here.  Mantra
    will apply any Instance/Light properties you set here to any objects which
    don't declare the property explicitly.

    """
    logger.debug("filterCamera")

    PYFILTER_MANAGER.runFilters("filterCamera")
Пример #20
0
def filterCamera():
    """Modify image related properties.

    Called just before the global properties are locked off for the render.
    This is usually prior to the declaration of any objects in the IFD.  If you
    change global properties after this, they probably will have no effect.

    Since mantra calls this function before any lights or instances are
    declared, you can set default light or instance properties here.  Mantra
    will apply any Instance/Light properties you set here to any objects which
    don't declare the property explicitly.

    """
    logger.debug("filterCamera")

    PYFILTER_MANAGER.runFilters("filterCamera")
Пример #21
0
        def wrapper(*args, **kwargs):
            func_name = func.__name__
            class_name = args[0].__class__.__name__

            msg = "{}.{}()".format(class_name, func_name)

            if isinstance(method_or_name, str):
                import mantra

                msg = "{} ({})".format(
                    msg,
                    mantra.property(method_or_name)[0]
                )

            logger.debug(msg)

            func(*args, **kwargs)
Пример #22
0
    def setProperty(self):
        """Set the property to the value."""
        # Don't do anything if the property isn't enabled.
        if not self.enabled:
            return

        import mantra

        # Is this property being applied to a specific render type.
        if self.rendertype is not None:
            # Get the rendertype for the current pass.
            rendertype = mantra.property("renderer:rendertype")[0]

            # If the type pattern doesn't match, abort.
            if not hou.patternMatch(self.rendertype, rendertype):
                return

        logger.debug(
            "Setting property '{}' to {}".format(self.name, self.value)
        )

        # Update the property value.
        mantra.setproperty(self.name, self.value)
Пример #23
0
    def filterCamera(self):
        """Apply camera properties."""
        render_type = getProperty("renderer:rendertype")

        if not self.all_passes and render_type != "beauty":
            logger.warning("Not a beauty render, skipping deepresolver")
            return

        if self.disable_deep_image:
            logger.info("Disabling deep resolver")
            setProperty("image:deepresolver", [])

        else:
            # Look for existing args.
            deep_args = getProperty("image:deepresolver")

            # If deep rendering is not enabled the args will be empty.
            if not deep_args:
                # If a resolver type and filename was passed then we will create
                # args for the resolver type to enable deep output.
                if self.deepresolver and self.filename:
                    deep_args = [self.deepresolver]

                # Log an error and abort.
                else:
                    logger.error(
                        "Cannot set deepresolver: deep output is not enabled")

                    return

            # Modify the args to include any passed along options.
            self._modifyDeepArgs(deep_args)

            logger.debug("Setting 'image:deepresolver': {}".format(" ".join(
                [str(arg) for arg in deep_args])))

            setProperty("image:deepresolver", deep_args)
Пример #24
0
def filterQuit():
    """Perform actions just before Mantra quits."""
    logger.debug("filterQuit")

    PYFILTER_MANAGER.runFilters("filterQuit")
Пример #25
0
def filterEndRender():
    """Perform actions just after the image has been rendered."""
    logger.debug("filterEndRender")

    PYFILTER_MANAGER.runFilters("filterEndRender")
Пример #26
0
def filterEndRender():
    """Perform actions just after the image has been rendered."""
    logger.debug("filterEndRender")

    PYFILTER_MANAGER.runFilters("filterEndRender")
Пример #27
0
def filterQuit():
    """Perform actions just before Mantra quits."""
    logger.debug("filterQuit")

    PYFILTER_MANAGER.runFilters("filterQuit")