use super::*;
use crate::world::BoneWeightFlags;
pub struct SdfModel {
id: Entity,
}
impl std::fmt::Debug for SdfModel {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Render")
.field("entity", &self.id.name())
.finish_non_exhaustive()
}
}
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
pub struct SdfProgram {
pub(crate) data: WorldData,
}
impl SdfProgram {
pub fn new(opcodes: &[u32], constants: &[f32]) -> Self {
let desc = ffi::v3::SdfProgramDesc {
num_opcodes: opcodes.len() as u32,
opcodes_ptr: opcodes.as_ptr() as u32,
num_constants: constants.len() as u32,
constants_ptr: constants.as_ptr() as u32,
};
Self {
data: WorldData::create_struct(ffi::CreateDataType::SdfProgram, &desc),
}
}
}
impl ValueConverterTrait<SdfProgram> for ValueConverter {
fn into_value(v: SdfProgram) -> Value {
<Self as ValueConverterTrait<WorldData>>::into_value(v.data)
}
fn from_value(v: &Value) -> SdfProgram {
SdfProgram {
data: <Self as ValueConverterTrait<WorldData>>::from_value(v),
}
}
}
impl SdfModel {
impl_world_accessor!(
SdfModel,
Program,
SdfProgram,
program,
ValueAccessorDataReadWrite
);
}
impl_world_component!(SdfModel);
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
pub struct SdfSkin {
pub(crate) data: WorldData,
}
impl SdfSkin {
pub fn new(
base_sdf_entity: Entity,
bone_entities: &[Entity],
rest_from_shape: &[BoneTransform],
replacement_mesh: Option<WorldMesh>,
bone_weight_flags: BoneWeightFlags,
bone_weight_bias: f32,
bone_weight_falloff: f32,
) -> Self {
let desc = ffi::v3::SdfSkinDesc2 {
base_sdf_entity: base_sdf_entity.0,
num_bone_entities: bone_entities.len() as u32,
bone_entities_ptr: bone_entities.as_ptr() as u32,
num_rest_from_shape: rest_from_shape.len() as u32,
rest_from_shape_ptr: rest_from_shape.as_ptr() as u32,
replacement_mesh: match replacement_mesh {
Some(mesh) => mesh.as_ffi(),
None => DataHandle::invalid().as_ffi(),
},
bone_weight_flags,
bone_weight_bias,
bone_weight_falloff,
reserved0: 0,
};
Self {
data: WorldData::create_struct(ffi::CreateDataType::SdfSkin2, &desc),
}
}
pub fn replacement_mesh(&self) -> Option<WorldMesh> {
let info: SdfSkinInfo = self.data.retrieve_data(RetrieveDataType::Info);
WorldMesh::try_from_ffi(info.replacement_mesh)
}
}
impl ValueConverterTrait<SdfSkin> for ValueConverter {
fn into_value(v: SdfSkin) -> Value {
<Self as ValueConverterTrait<WorldData>>::into_value(v.data)
}
fn from_value(v: &Value) -> SdfSkin {
SdfSkin {
data: <Self as ValueConverterTrait<WorldData>>::from_value(v),
}
}
}