diff --git a/src/load_roblox.rs b/src/load_roblox.rs index c2064eb..7b9c95c 100644 --- a/src/load_roblox.rs +++ b/src/load_roblox.rs @@ -70,29 +70,64 @@ impl std::hash::Hash for RobloxTextureTransform { self.scale_v.to_ne_bytes().hash(state); } } -#[derive(Hash)] +#[derive(Clone,Copy,PartialEq)] +struct RobloxColorAndTextureTransform{ + transform:RobloxTextureTransform, + color:glam::Vec4, +} +impl std::cmp::Eq for RobloxColorAndTextureTransform{}//???? +impl std::default::Default for RobloxColorAndTextureTransform{ + fn default() -> Self { + Self{ + transform:RobloxTextureTransform::default(), + color:glam::Vec4::ONE, + } + } +} +impl std::hash::Hash for RobloxColorAndTextureTransform { + fn hash(&self, state: &mut H) { + self.transform.hash(state); + for &el in self.color.as_ref().iter() { + el.to_ne_bytes().hash(state); + } + } +} struct PartFaceTextureDescription{ texture:u32, + color:glam::Vec4, transform:RobloxTextureTransform, } type PartTextureDescription=[Option;6]; -#[derive(Hash,Eq,PartialEq)] +#[derive(PartialEq)] struct RobloxUnitCubeGenerationData{ texture:Option, + color:glam::Vec4, faces:[Option;6], } +impl std::cmp::Eq for RobloxUnitCubeGenerationData{}//???? impl std::default::Default for RobloxUnitCubeGenerationData{ fn default() -> Self { Self{ texture:None, + color:glam::Vec4::ONE, faces:[Some(RobloxTextureTransform::default());6], } } } +impl std::hash::Hash for RobloxUnitCubeGenerationData { + fn hash(&self, state: &mut H) { + self.texture.hash(state); + for &el in self.color.as_ref().iter() { + el.to_ne_bytes().hash(state); + } + self.faces.hash(state); + } +} impl RobloxUnitCubeGenerationData{ fn empty() -> Self { Self{ texture:None, + color:glam::Vec4::ONE, faces:[None,None,None,None,None,None], } } @@ -156,9 +191,13 @@ pub fn generate_modeldatas_roblox(dom:rbx_dom_weak::WeakDom) -> Result<(Vec(){ let texture_id=if let Some(&texture_id)=texture_id_from_asset_id.get(&asset_id.0){ @@ -171,7 +210,7 @@ pub fn generate_modeldatas_roblox(dom:rbx_dom_weak::WeakDom) -> Result<(Vec Result<(Vec(size.x,size.y),//front _=>(1.,1.), }; - roblox_texture_transform=RobloxTextureTransform{ - offset_u:*ox/(*sx),offset_v:*oy/(*sy), - scale_u:size_u/(*sx),scale_v:size_v/(*sy), + roblox_texture_transform=RobloxColorAndTextureTransform{ + transform:RobloxTextureTransform{ + offset_u:*ox/(*sx),offset_v:*oy/(*sy), + scale_u:size_u/(*sx),scale_v:size_v/(*sy), + }, + color:glam::vec4(decal_color3.r as f32/255f32, decal_color3.g as f32/255f32, decal_color3.b as f32/255f32, 1.0-*decal_transparency), }; } } - //I can alos put the color into here and generate the vertices with the color part_texture_description[face as usize]=Some(PartFaceTextureDescription{ texture:texture_id, - transform:roblox_texture_transform, + color:roblox_texture_transform.color, + transform:roblox_texture_transform.transform, }); }else{ println!("goofy ahh roblox gave NormalId {}", face); @@ -226,6 +268,7 @@ pub fn generate_modeldatas_roblox(dom:rbx_dom_weak::WeakDom) -> Result<(Vec Result<(VecNone, } }); - let mut new_modeldatas=crate::model::generate_modeldatas(primitives::generate_partial_unit_cube(unit_cube_generation_data),ModelData::COLOR_FLOATS_WHITE); + let mut new_modeldatas=crate::model::generate_modeldatas(primitives::generate_partial_unit_cube(unit_cube_generation_data),*roblox_unit_cube_generation_data.color.as_ref()); new_modeldatas[0].texture=roblox_unit_cube_generation_data.texture; let model_id=modeldatas.len(); modeldatas.append(&mut new_modeldatas);