implement texture_loader
This commit is contained in:
parent
b5ab8f377d
commit
05e609521a
@ -21,6 +21,6 @@ fn load_dom<R:Read>(input:R)->Result<rbx_dom_weak::WeakDom,Error>{
|
||||
}
|
||||
}
|
||||
|
||||
pub fn read<R:Read>(input:R)->Result<strafesnet_common::map::CompleteMap,Error>{
|
||||
Ok(rbx::convert(load_dom(input)?))
|
||||
pub fn read<R:Read,F:FnMut(&str)->Option<strafesnet_common::model::TextureId>>(input:R,acquire_id:F)->Result<strafesnet_common::map::CompleteMap,Error>{
|
||||
Ok(rbx::convert(load_dom(input)?,acquire_id))
|
||||
}
|
39
src/rbx.rs
39
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<Self,Self::Err>{
|
||||
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::<u64>(){
|
||||
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 convert<F:FnMut(&str)->Option<model::TextureId>>(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::<u64,RenderConfigId>::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::<RobloxAssetId>(){
|
||||
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(),
|
||||
|
Loading…
Reference in New Issue
Block a user