opengl – Is it the code within the vertex shader or the animation info that’s incorrect?

[ad_1]

I do not know what else to attempt! I am making an attempt to do skeleton animation with Rust, OpenGL (particularly the gl library), gltf information (and the library of the identical identify), in addition to a library known as glam to create the 4×4 matrices.
And I don’t know easy methods to make issues work, I already posted this query right here, on stackoverflow, I requested chatgpt and nothing labored! I’ve to animate fashions which can be too heavy to make use of morph goal! The animations are lengthy and sophisticated, I want this to work!

I loaded the interpretation, rotation and inverted_bind_matrices info utilizing the operate:

fn CarregarAnimacao(modelo : &str) -> (Vec<Vec<f32>>,Vec<Vec<f32>>,Vec<[[f32; 4]; 4]>){
    let (knowledge, buffers, _) = gltf::import(format!("extras/{}.gltf",modelo)).unwrap();
    let mut translate : Vec<Vec<f32>> = Vec::new();
    let mut rotations : Vec<Vec<f32>> = Vec::new();
    let mut scales : Vec<[[f32; 4]; 4]> = Vec::new();
    for a in knowledge.animations(){
        for c in a.channels(){
            let r = c.reader(|buffer| Some(&buffers[buffer.index()]));
            let okay = if let Some(outputs) = r.read_outputs(){
                match outputs{
                    gltf::animation::util::ReadOutputs::Translations(translation) => {
                        translation.for_each(|tr|{
                            translate.push(tr.into());
                        });
                    },
                    gltf::animation::util::ReadOutputs::Rotations(rotation) => {
                        for r in rotation.into_f32(){
                            rotations.push(r.into());
                        }
                    },
                    different => ()
                }
            };
        }
    }
    for a in knowledge.skins(){
        let r = a.reader(|buffer| Some(&buffers[buffer.index()]));
        let okay = if let Some(gltf::accessor::Iter::Commonplace(iter)) = r.read_inverse_bind_matrices(){
            for v in iter{
                scales.push(v);
            }
        };
    }
    (rotations,translate,scales)
}

Then I used uniforms to ship the data to the shader like this:

    let andar = CarregarAnimacao("EXEMPLO"); // Rotação, Translate, Inverse Bind Matrices
    let tam_anim = 2; // Numero de Frames
    println!("ROTAÇÃO : {:?}", andar.0);
    println!("TRANSLAÇÃO : {:?}", andar.1);
    println!("MATRIZES : {:?}", andar.2);
    let mut frm = 1;
    unsafe{
        //gl::UniformMatrix4fv(gl::GetUniformLocation(shader,std::ffi::CString::new("ANIMACAO1").unwrap().as_ptr()), 65, gl::FALSE, andar.2.as_ptr() as *const f32);
        let mut M_andar : Vec<[[f32; 4]; 4]> = Vec::new();
        for i in 0..3{ // Numero de Ossos
            frm = i*tam_anim+1;
            gl::Uniform3f(gl::GetUniformLocation(shader,std::ffi::CString::new(format!("ANIMACAO2[{}]",i)).unwrap().as_ptr()), andar.1[frm][0], andar.1[frm][1], andar.1[frm][2]);
            //gl::Uniform4f(gl::GetUniformLocation(shader,std::ffi::CString::new(format!("ANIMACAO3[{}]",i)).unwrap().as_ptr()), andar.0[i*tam_anim+1][0], andar.0[i*tam_anim+1][1], -andar.0[i*tam_anim+1][2], andar.0[i*tam_anim+1][3]);
            let teste = glam::f32::Mat4::from_quat(glam::f32::Quat::from_xyzw(andar.0[frm][0],andar.0[frm][1],andar.0[frm][2],andar.0[frm][3]));
            let tm = [[teste.x_axis[0],teste.x_axis[1],teste.x_axis[2],teste.x_axis[3]],[teste.y_axis[0],teste.y_axis[1],teste.y_axis[2],teste.y_axis[3]],[teste.z_axis[0],teste.z_axis[1],teste.z_axis[2],teste.z_axis[3]],[teste.w_axis[0],teste.w_axis[1],teste.w_axis[2],teste.w_axis[3]]];
            M_andar.push(tm);
        }
        println!("GERADAS : {:?}",M_andar);
        gl::UniformMatrix4fv(gl::GetUniformLocation(shader,std::ffi::CString::new("ANIMACAO").unwrap().as_ptr()), 3, gl::FALSE, M_andar.as_ptr() as *const f32);
        gl::UniformMatrix4fv(gl::GetUniformLocation(shader,std::ffi::CString::new("CORRECAO").unwrap().as_ptr()), 3, gl::FALSE, andar.2.as_ptr() as *const f32);
    }

The issue is that I now not know what works and what would not! I’ve already examined so many variations of easy methods to apply the code in vertex_shader that I simply do not know what to jot down right here! I feel both the animation info is totally incorrect or all of the methods I’ve interpreted the information have simply turned out to be fully incompetent! Which one is happening?

[ad_2]

Categories:

Leave a Reply

Your email address will not be published. Required fields are marked *