use cxx::UniquePtr;
#[cxx::bridge(namespace = "hydra_rs")]
mod ffi {
unsafe extern "C++" {
include!("hydra_bridge.h");
type SceneIndex;
fn populate_from_path(usd_path: &str) -> Result<UniquePtr<SceneIndex>>;
fn list_render_delegate_ids() -> UniquePtr<CxxVector<CxxString>>;
fn render_to_rgba(
usd_path: &str,
render_delegate_id: &str,
width: u32,
height: u32,
) -> Result<UniquePtr<CxxVector<u8>>>;
fn stage_root(self: &SceneIndex) -> String;
fn prim_count(self: &SceneIndex) -> usize;
fn prim_paths(self: &SceneIndex) -> UniquePtr<CxxVector<CxxString>>;
}
}
pub struct SceneIndex {
inner: UniquePtr<ffi::SceneIndex>,
}
impl SceneIndex {
pub fn from_path(path: &str) -> Result<Self, cxx::Exception> {
Ok(Self {
inner: ffi::populate_from_path(path)?,
})
}
pub fn stage_root(&self) -> String {
self.inner.stage_root()
}
pub fn prim_count(&self) -> usize {
self.inner.prim_count()
}
pub fn prim_paths(&self) -> Vec<String> {
self.inner
.prim_paths()
.iter()
.map(|s| s.to_string())
.collect()
}
}
pub fn list_render_delegates() -> Vec<String> {
ffi::list_render_delegate_ids()
.iter()
.map(|s| s.to_string())
.collect()
}
pub fn render_to_rgba(
usd_path: &str,
render_delegate: &str,
width: u32,
height: u32,
) -> Result<Vec<u8>, cxx::Exception> {
let bytes = ffi::render_to_rgba(usd_path, render_delegate, width, height)?;
Ok(bytes.iter().copied().collect())
}