SiebenCorgie / ori-engine

A small engine written in rust + vulkan.
Other
7 stars 1 forks source link

Make the texture import and material creation better #9

Closed SiebenCorgie closed 7 years ago

SiebenCorgie commented 7 years ago

Currently you need something like this:

    ///Creating a new material, currently a bit ugly
    {
        let render_inst = render.clone();
        let mut render_lck = render_inst.lock().expect("failed to hold renderer");
        //Create a second material
        //create new texture
        let new_texture = core::resources::texture::TextureBuilder::from_image(
            "/share/3DFiles/TextureLibary/Comix/Mariuhana.jpg",
            (*render_lck).get_device(),
            (*render_lck).get_queue(),
            settings.clone()
        ).build_with_name("new_texture");
        asset_manager.get_texture_manager().add_texture(new_texture);

        let (_ , normal, physical) = asset_manager.get_texture_manager().get_fallback_textures();

        let texture_in_manager = asset_manager.get_texture_manager().get_texture("new_texture");

        let mut new_material = core::resources::material::MaterialBuilder::new(
            Some(texture_in_manager),
            Some(normal),
            Some(physical),
            None,
            asset_manager.get_texture_manager().get_none()
        ).build(
            "new_material",
            "DefaultPipeline",
            (*render_lck).get_pipeline_manager(),
            (*render_lck).get_uniform_manager(),
            (*render_lck).get_device(),
            (*render_lck).get_queue(),
            settings.clone()
        );

        //add to the manager
        asset_manager.get_material_manager().add_material(new_material);
    }

to create a new_texture and add it to a new_material and finally something like this:

            let mut ape_scene = asset_manager.get_scene_manager().get_scene("Ape").expect("no Apes :(");
            for i in ape_scene.get_all_meshes().iter(){
                let mesh_inst = i.clone();
                let mut mesh_lck = mesh_inst.lock().expect("failed to change material");
                (*mesh_lck).set_material("new_material");
            }

to add it to the engine. This is extremely inefficient. I'll write a fronted for a nicer way to handle this.

SiebenCorgie commented 7 years ago

This was added, the run-time pipeline change is still possible.