Asset Management

Managing assets like images, 3D models, and custom fonts is a critical part of building rich, interactive plugins. The Foresight Development Kit provides several ways to handle these assets, allowing you to choose the best balance between application portability and runtime flexibility.

Remote Loading for Dynamic Content

The most flexible way to manage assets is to fetch them from a remote web server at runtime. This is the ideal approach for large 3D models, point clouds, or any content that changes frequently.

By using standard networking libraries within asynchronous Statements or Tools, you can download asset data on-demand. This keeps the initial plugin download small and allows the application to handle large datasets without bloating the local binary. We recommend implementing a local caching strategy for frequently used remote assets.

Embedding Assets for Portability

For assets essential to plugin functionality, such as UI icons or basic geometric primitives, you can embed them directly into the plugin binary. This ensures critical assets are always available, even without a network connection.

The Foresight Development Kit supports the bevy_embedded_assets crate for this purpose. When you place your files in an assets folder within your plugin crate and register the EmbeddedAssetPlugin, your assets become accessible via a specialized embedded:// URI.

use bevy_embedded_assets::EmbeddedAssetPlugin;

impl FoundryPlugin for MyPlugin {
    fn build(self, app: &mut FoundryPluginBuilder) {
        // Register the embedded asset source
        app.add_plugins(EmbeddedAssetPlugin::default());
        
        // Assets are now available at: "embedded://my_plugin/icons/star.png"
    }
}

Leveraging the Bevy Asset System

Because the Foresight Development Kit is built on top of Bevy, you have access to a robust, multi-threaded asset pipeline. Out of the box, the SDK supports standard formats like PNG/JPEG for textures, GLTF/GLB for 3D models, and TTF/OTF for typography.

If your plugin requires a proprietary file format, you can also define your own custom asset types and loaders. This allows you to treat your specialized data just like any other engine asset, benefiting from Bevy’s built-in hot reloading and asynchronous management.

Best Practices for Asset Performance

To maintain the high-performance standards of the Foresight Development Kit, keep these guidelines in mind:

  • Optimize Early: Always compress textures and simplify meshes before including them in your plugin. Every megabyte saved improves the client’s startup time and memory footprint.
  • Use Embedding Judiciously: While embedding is convenient, it increases the size of the final binary. Use it for UI and core functionality, but rely on remote streaming for anything that isn’t required for the plugin to launch.
  • Manage Lifecycle: Be mindful of when assets are loaded into GPU memory. For large models, consider loading them only when the associated tool or editor is active, and ensure they are released when no longer needed.