Item Attributes Renderer
The Item Attributes Renderer plugin serves as a crucial component in the Art Engine's rendering pipeline. Its primary function is to render the attributes generated during the artwork generation process in a human-readable and structured format. This rendered data can then be used by exporters and other downstream processes to understand and utilize the attributes associated with each generated artwork effectively.
Adding the plugin
- Import the plugin object:
const { ArtEngine, renderers } = require("@hashlips-lab/art-engine");
- Setup a base path:
const BASE_PATH = __dirname;
- Add the plugin to an instance of the Art Engine:
const ae = new ArtEngine({
cachePath: `${BASE_PATH}/cache`,
outputPath: `${BASE_PATH}/output`,
useCache: false,
renderers: [
new renderers.ItemAttributesRenderer({
name: (itemUid: string) => `Artwork ${itemUid}`,
description: (attributes) => `This artwork features ${attributes["Color"]} colors.`,
});
// Add more renderers if needed...
]
// Add inputs, generators, and exporters as required...
});
Parameters
name
(optional): A function that takes an item's unique ID (itemUid
) as input and returns a custom name for the artwork associated with that item. If not provided, a default empty string will be used as the name.description
(optional): A function that takes the rendered attributes as input and returns a custom description for the artwork based on those attributes. If not provided, a default empty string will be used as the description.
Interfaces
Base
This plugin adheres to the base renderer interface called RendererInterface<RendererDataType>
.
Custom
The AttributesRendererInterface is a custom interface meticulously crafted for the Item Attributes Renderer. It encapsulates the structure of rendered item attributes:
export default interface AttributesRendererInterface {
dna: string[];
name: string;
description: string;
attributes: {
[traitName: string]: string[];
};
}
The Item Attributes Renderer plugin serves as a prime exemplar of renderer functionality within the Art Engine ecosystem. It adheres to the core renderer interface and specializes in rendering item attributes in a structured, human-friendly format.
The Item Attributes Renderer class is defined as follows:
export class ItemAttributesRenderer
implements RendererInterface<AttributesRendererInterface> {
// Implementation details
}
This interface signifies that the rendered output comprises a DNA identifier, name, description, and a collection of attributes associated with each trait.
The Item Attributes Renderer capitalizes on the provided attributesGetter to access the data generated by the Item Attributes Generator. By processing this data, the renderer constructs and renders the item attributes in a comprehensible manner.