diff --git a/src/lib.rs b/src/lib.rs index 4dc3e27..3b35ed8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -21,6 +21,6 @@ fn load_dom(input:R)->Result{ } } -pub fn read(input:R)->Result{ - Ok(rbx::convert(load_dom(input)?)) +pub fn readOption>(input:R,acquire_id:F)->Result{ + Ok(rbx::convert(load_dom(input)?,acquire_id)) } \ No newline at end of file diff --git a/src/rbx.rs b/src/rbx.rs index fe9e9d3..ec8c051 100644 --- a/src/rbx.rs +++ b/src/rbx.rs @@ -337,22 +337,6 @@ fn get_attributes(object:&rbx_dom_weak::Instance,can_collide:bool,velocity:Plana } } -struct RobloxAssetId(u64); -struct RobloxAssetIdParseErr; -impl std::str::FromStr for RobloxAssetId{ - type Err=RobloxAssetIdParseErr; - fn from_str(s:&str)->Result{ - let regman=lazy_regex::regex!(r"(\d+)$"); - if let Some(captures) = regman.captures(s) { - if captures.len()==2{//captures[0] is all captures concatenated, and then each individual capture - if let Ok(id) = captures[0].parse::(){ - return Ok(Self(id)); - } - } - } - Err(RobloxAssetIdParseErr) - } -} #[derive(Clone,Copy,PartialEq)] struct RobloxTextureTransform{ offset_u:f32, @@ -421,7 +405,7 @@ struct ModelOwnedAttributes{ color:model::Color4,//transparency is in here transform:Planar64Affine3, } -pub fn convert(dom:rbx_dom_weak::WeakDom)->map::CompleteMap{ +pub fn convertOption>(dom:rbx_dom_weak::WeakDom,mut acquire_id:F)->map::CompleteMap{ let mut modes_builder=ModesBuilder::default(); let mut models1=Vec::new(); @@ -437,7 +421,6 @@ pub fn convert(dom:rbx_dom_weak::WeakDom)->map::CompleteMap{ //TODO: some sort of thing like RobloxResources that describes where to get each resource //this would be another dependency built for downloading resources to keep this one clean let mut unique_render_groups=vec![RenderConfig::default()]; - let mut render_id_from_asset_id=HashMap::::new(); let textureless_render_group=RenderConfigId::new(0); let mut object_refs=Vec::new(); @@ -520,18 +503,14 @@ pub fn convert(dom:rbx_dom_weak::WeakDom)->map::CompleteMap{ decal.properties.get("Color3"), decal.properties.get("Transparency"), ) { - if let Ok(asset_id)=content.clone().into_string().parse::(){ - let render_id=textureless_render_group; - /* TODO: textures - let render_id=if let Some(&render_id)=render_id_from_asset_id.get(&asset_id.0){ - render_id - }else{ - let render_id=RenderConfigId::new(unique_render_groups.len() as u32); - render_id_from_asset_id.insert(asset_id.0,render_id); - unique_render_groups.push(RenderConfig::texture(asset_id.0)); - render_id + if let Some(texture_id)=acquire_id(content.as_ref()){ + //this is equivalent to a get_or_create pattern because there is a singular no-texture RenderId + //so RenderId==TextureId+1 + //not the most failsafe code but this is just for the map tool lmao + if unique_render_groups.len()==texture_id.get() as usize+1{ + unique_render_groups.push(RenderConfig::texture(texture_id)); }; - */ + let render_id=RenderConfigId::new(texture_id.get()+1); let normal_id=normalid.to_u32(); if normal_id<6{ let (roblox_texture_color,roblox_texture_transform)=if decal.class=="Texture"{ @@ -733,7 +712,7 @@ pub fn convert(dom:rbx_dom_weak::WeakDom)->map::CompleteMap{ } }).collect(); map::CompleteMap{ - render_configs:vec![RenderConfig::default()],//asset_id_from_texture_id.iter().map(|t|t.to_string()).collect(), + render_configs:unique_render_groups,//asset_id_from_texture_id.iter().map(|t|t.to_string()).collect(), meshes, models, modes:modes_builder.build(),