nem0 / OpenFBX

Lightweight open source FBX importer
MIT License
1.15k stars 135 forks source link

Typo in ShapeImpl::postprocess making normals incorrectly parsed for blend shapes #75

Closed SoapyMan closed 2 years ago

SoapyMan commented 2 years ago

I have found a small mistake in the code that made blend shape normals look ugly.

    vertices = geom->vertices;
    normals = geom->normals;

    Vec3* vr = &allocator.vec3_tmp[0];
    Vec3* nr = &allocator.vec3_tmp2[0];
    int* ir = &allocator.int_tmp[0];
    for (int i = 0, c = (int)allocator.int_tmp.size(); i < c; ++i)
    {
        int old_idx = ir[i];
        GeometryImpl::NewVertex* n = &geom->to_new_vertices[old_idx];
        if (n->index == -1) continue; // skip vertices which aren't indexed.
        while (n)
        {
            vertices[n->index] = vertices[n->index] + vr[i];
            normals[n->index] = vertices[n->index] + nr[i];   // <------------------------- line 2781, there should be 'normals' instead
            n = n->next;
        }
    }

P.S. This project is great! Have a good day!

nem0 commented 2 years ago

Thanks, fixed.