From ee1b7fd3bc66501b252ce9e3e5ba89ac9aa54632 Mon Sep 17 00:00:00 2001 From: omniscient <17525998+omnisci3nce@users.noreply.github.com> Date: Sat, 10 Aug 2024 23:18:22 +1000 Subject: more work on bindings and ral --- bindgen/rust/src/lib.rs | 50 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 2 deletions(-) (limited to 'bindgen/rust/src/lib.rs') diff --git a/bindgen/rust/src/lib.rs b/bindgen/rust/src/lib.rs index f2e177f..dd83293 100644 --- a/bindgen/rust/src/lib.rs +++ b/bindgen/rust/src/lib.rs @@ -4,6 +4,7 @@ #![cfg_attr(docsrs, feature(doc_cfg))] pub use celeritas_sys as ffi; +use glam::Vec3; /// Commonly used types pub mod prelude; @@ -17,14 +18,20 @@ use std::{ fs::{self, File}, io::Write, path::Path, + ptr::addr_of_mut, }; use celeritas_sys::{ - Camera, Camera_Create, Core_Bringup, Core_Shutdown, DirectionalLight, PointLight, RenderEnt, - Transform, Vec3, + Core_Bringup, Core_Shutdown, DirectionalLight, Material, Material_Insert, Model, PointLight, + TextureHandle, Transform, }; use serde::{Deserialize, Serialize}; +pub trait IntoFFI { + type FFIType; + unsafe fn into_ffi(self) -> Self::FFIType; +} + /// Wrapper around a string that is the path to a gltf model **relative** to the configured /// `ASSETS` folder #[derive(Debug, Clone, Serialize, Deserialize)] @@ -103,3 +110,42 @@ bitflags::bitflags! { } } + +type M = Material; +/* +pub name: [::std::os::raw::c_char; 64usize], +pub kind: MaterialKind, +pub base_colour: Vec3, +pub metallic: f32_, +pub roughness: f32_, +pub ambient_occlusion: f32_, +pub albedo_map: TextureHandle, +pub normal_map: TextureHandle, +pub metallic_roughness_map: TextureHandle, +pub ambient_occlusion_map: TextureHandle, */ + +#[derive(Debug, Clone, Default, PartialEq)] +pub struct PBRMaterial { + pub name: String, + pub base_colour: glam::Vec3, + pub metallic: f32, + pub roughness: f32, + pub ambient_occlusion: f32, + pub albedo_map: Option, + pub normal_map: Option, + pub metallic_roughness_map: Option, + pub ambient_occlusion_map: Option, +} +impl PBRMaterial { + /// Creates the material in the C core returning a handle to it + pub fn create(mat: Self) -> ffi::MaterialHandle { + let mut ffi_mat = ffi::Material::from(mat); + unsafe { Material_Insert(addr_of_mut!(ffi_mat)) } + } +} + +impl From for ffi::Material { + fn from(value: PBRMaterial) -> Self { + todo!("impl conv for materials") + } +} -- cgit v1.2.3-70-g09d2