9.6 KiB
Developer Guide: Architecture
This document provides a high-level overview of the Asset Processor Tool's architecture and core components for developers.
High-Level Architecture
The Asset Processor Tool is designed to process 3D asset source files into a standardized library format. Its high-level architecture consists of:
- Core Processing Initiation (
processing_engine.py): TheProcessingEngineclass acts as the entry point for an asset processing task. It initializes and runs aPipelineOrchestrator. - Pipeline Orchestration (
processing/pipeline/orchestrator.py): ThePipelineOrchestratormanages a sequence of discrete processing stages. It creates anAssetProcessingContextfor each asset and passes this context through each stage. - Processing Stages (
processing/pipeline/stages/): Individual modules, each responsible for a specific task in the pipeline (e.g., filtering files, processing maps, merging channels, organizing output). They operate on theAssetProcessingContext. - Prediction System: Responsible for analyzing input files and generating the initial
SourceRulehierarchy with predicted values. This system utilizes a base handler (gui/base_prediction_handler.py::BasePredictionHandler) with specific implementations:- Rule-Based Predictor (
gui/prediction_handler.py::RuleBasedPredictionHandler): Uses predefined rules from presets to classify files and determine initial processing parameters. - LLM Predictor (
gui/llm_prediction_handler.py::LLMPredictionHandler): An experimental alternative that uses a Large Language Model (LLM) to interpret file contents and context to predict processing parameters.
- Rule-Based Predictor (
- Configuration System (
Configuration): Handles loading core settings (including centralized type definitions and LLM-specific configuration) and merging them with supplier-specific rules defined in JSON presets and the persistentconfig/suppliers.jsonfile. - Multiple Interfaces: Provides different ways to interact with the tool:
- Graphical User Interface (GUI)
- Command-Line Interface (CLI) - Note: The primary CLI execution logic (
run_cliinmain.py) is currently non-functional/commented out post-refactoring. - Directory Monitor for automated processing.
The GUI acts as the primary source of truth for processing rules, coordinating the generation and management of the
SourceRulehierarchy before sending it to theProcessingEngine. It accumulates prediction results from multiple input sources before updating the view. The Monitor interface can also generateSourceRuleobjects (usingutils/prediction_utils.py) to bypass the GUI for automated workflows.
- Optional Integration: Includes scripts (
blenderscripts/) for integrating with Blender. Logic for executing these scripts was intended to be centralized inutils/blender_utils.py, but this utility has not yet been implemented.
Hierarchical Rule System
A key addition to the architecture is the Hierarchical Rule System, which provides a dynamic layer of configuration that can override the static settings loaded from presets. This system is represented by a hierarchy of rule objects: SourceRule, AssetRule, and FileRule.
- SourceRule: Represents rules applied at the top level, typically corresponding to an entire input source (e.g., a ZIP file or folder).
- AssetRule: Represents rules applied to a specific asset within a source (a source can contain multiple assets).
- FileRule: Represents rules applied to individual files within an asset.
This hierarchy allows for fine-grained control over processing parameters. The GUI's prediction logic generates this hierarchy with initial predicted values for overridable fields based on presets and file analysis. The ProcessingEngine (via the PipelineOrchestrator and its stages) then operates solely on the explicit values provided in this SourceRule object and static configuration, without internal prediction or fallback logic.
Core Components
config/app_settings.json: Defines core, global settings, constants, and centralized definitions for allowed asset and file types (ASSET_TYPE_DEFINITIONS,FILE_TYPE_DEFINITIONS), including metadata like colors and descriptions. This replaces the oldconfig.pyfile.config/suppliers.json: A persistent JSON file storing known supplier names for GUI auto-completion.Presets/*.json: Supplier-specific JSON files defining rules for file interpretation and initial prediction.configuration.py(Configurationclass): Loadsconfig/app_settings.jsonsettings and merges them with a selected preset, pre-compiling regex patterns for efficiency. This static configuration is used by the processing pipeline.rule_structure.py: Defines theSourceRule,AssetRule, andFileRuledataclasses used to represent the hierarchical processing rules.gui/: Directory containing modules for the Graphical User Interface (GUI), built with PySide6. TheMainWindow(main_window.py) acts as a coordinator, orchestrating interactions between various components. Key GUI components include:main_panel_widget.py::MainPanelWidget: Contains the primary controls for loading sources, selecting presets, viewing/editing rules, and initiating processing.preset_editor_widget.py::PresetEditorWidget: Provides the interface for managing presets.log_console_widget.py::LogConsoleWidget: Displays application logs.unified_view_model.py::UnifiedViewModel: Implements theQAbstractItemModelfor the hierarchical rule view, holdingSourceRuledata and managing display logic (coloring, etc.). Caches configuration data for performance.rule_hierarchy_model.py::RuleHierarchyModel: A simpler model used internally by theUnifiedViewModelto manage theSourceRuledata structure.delegates.py: Contains customQStyledItemDelegateimplementations for inline editing in the rule view.asset_restructure_handler.py::AssetRestructureHandler: Handles complex model updates when a file's target asset is changed via the GUI, ensuring theSourceRulehierarchy is correctly modified.base_prediction_handler.py::BasePredictionHandler: Abstract base class for prediction logic.prediction_handler.py::RuleBasedPredictionHandler: Generates the initialSourceRulehierarchy based on presets and file analysis. Inherits fromBasePredictionHandler.llm_prediction_handler.py::LLMPredictionHandler: Experimental predictor using an LLM. Inherits fromBasePredictionHandler.llm_interaction_handler.py::LLMInteractionHandler: Manages communication with the LLM service for the LLM predictor.
processing_engine.py(ProcessingEngineclass): The entry-point class that initializes and runs thePipelineOrchestratorfor a givenSourceRuleandConfiguration.processing/pipeline/orchestrator.py(PipelineOrchestratorclass): Manages the sequence of processing stages, creating and passing anAssetProcessingContextthrough them.processing/pipeline/asset_context.py(AssetProcessingContextclass): A dataclass holding all data and state for the processing of a single asset, passed between stages.processing/pipeline/stages/: Directory containing individual processing stage modules, each handling a specific part of the pipeline (e.g.,IndividualMapProcessingStage,MapMergingStage).main.py: The main entry point for the application. Primarily launches the GUI. Contains commented-out/non-functional CLI logic (run_cli).monitor.py: Implements the directory monitoring feature usingwatchdog. It now processes archives asynchronously using aThreadPoolExecutor, leveragingutils.prediction_utils.pyfor rule generation andutils.workspace_utils.pyfor workspace management before invoking theProcessingEngine.blenderscripts/: Contains Python scripts designed to be executed within Blender for post-processing tasks.utils/: Directory containing utility modules:workspace_utils.py: Contains functions likeprepare_processing_workspacefor handling temporary directories and archive extraction.prediction_utils.py: Contains functions likegenerate_source_rule_from_archiveused by the monitor for rule-based prediction.blender_utils.py: (Intended location for Blender script execution logic, currently not implemented).
Processing Pipeline (Simplified Overview)
The asset processing pipeline, initiated by processing_engine.py and managed by PipelineOrchestrator, executes a series of stages for each asset defined in the SourceRule. An AssetProcessingContext object carries data between stages. The typical sequence is:
- Supplier Determination: Identify the effective supplier.
- Asset Skip Logic: Check if the asset should be skipped.
- Metadata Initialization: Set up initial asset metadata.
- File Rule Filtering: Determine which files to process.
- Pre-Map Processing:
- Gloss-to-Roughness Conversion.
- Alpha Channel Extraction.
- Normal Map Green Channel Inversion.
- Individual Map Processing: Handle individual maps (scaling, variants, stats, naming).
- Map Merging: Combine channels from different maps.
- Metadata Finalization & Save: Generate and save
metadata.json(temporarily). - Output Organization: Copy all processed files to final output locations.
External steps like workspace preparation/cleanup and optional Blender script execution bracket this core pipeline. This architecture allows for a modular design, separating configuration, rule generation/management, and core processing execution.