Skip to main content

render_to_buffer_cached

Function render_to_buffer_cached 

Source
pub fn render_to_buffer_cached(
    object_dir: &Path,
    camera_transform: &Transform,
    object_rotation: &ObjectRotation,
    config: &RenderConfig,
    cache: &mut ModelCache,
) -> Result<RenderOutput, RenderError>
Expand description

Render with model caching support for efficient multi-viewpoint rendering.

This function tracks which models have been loaded and provides performance insights. The current batch API is a queue-oriented wrapper, not a persistent renderer, so this function and render_to_buffer() use the same underlying headless app-per-render path today.

§Arguments

  • object_dir - Path to YCB object directory
  • camera_transform - Camera position and orientation
  • object_rotation - Rotation to apply to the object
  • config - Render configuration
  • cache - Model cache to track loaded assets

§Returns

RenderOutput with rendered RGBA and depth data

§Example

use bevy_sensor::{render_to_buffer_cached, cache::ModelCache, RenderConfig, ObjectRotation};
use std::path::PathBuf;

let mut cache = ModelCache::new();
let object_dir = PathBuf::from("/tmp/ycb/003_cracker_box");
let config = RenderConfig::tbp_default();
let viewpoints = bevy_sensor::generate_viewpoints(&ViewpointConfig::default());

// First render: loads from disk and caches
let output1 = render_to_buffer_cached(
    &object_dir,
    &viewpoints[0],
    &ObjectRotation::identity(),
    &config,
    &mut cache,
)?;

// Subsequent renders: tracks in cache
for viewpoint in &viewpoints[1..] {
    let output = render_to_buffer_cached(
        &object_dir,
        viewpoint,
        &ObjectRotation::identity(),
        &config,
        &mut cache,
    )?;
}

§Note

This function uses the same rendering engine as render_to_buffer(). The current batch API preserves ordering and output structure but does not yet reuse a live Bevy renderer across calls.

use bevy_sensor::{render_batch, batch::BatchRenderRequest, BatchRenderConfig, RenderConfig, ObjectRotation};

let requests: Vec<_> = viewpoints.iter().map(|vp| {
    BatchRenderRequest {
        object_dir: object_dir.clone(),
        viewpoint: *vp,
        object_rotation: ObjectRotation::identity(),
        render_config: RenderConfig::tbp_default(),
    }
}).collect();

let outputs = render_batch(requests, &BatchRenderConfig::default())?;