nem0 / OpenFBX

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

Add (proper) support for "ByPolygon" mapping for vertex data #84

Closed TomTheFurry closed 1 year ago

TomTheFurry commented 1 year ago

While the parser does parse the "ByPolygon" property into the corresponding GeometryImpl::BY_POLYGON enum, the static void splat(...) does not yet handle it.

A rough example of how it can be impl. see below snippets from our internal C# port:

        else if (mapping == Geometry.VertexDataMapping.ByPolygon)
        {
            // C# Specific: We added support for this mapping type as we need it. No clue if it's correct though.
            output.Clear();
            var polygonIndex = 0;
            foreach (int t in original_indices)
            {
                if (indices.Count == 0)
                {
                    output.Add(polygonIndex < data.Count ? data[polygonIndex] : default);
                }
                else
                {
                    output.Add(
                        polygonIndex < data.Count && indices[polygonIndex] >= 0
                            ? data[indices[polygonIndex]]
                            : default
                    );
                }

                if (t < 0)
                {
                    polygonIndex++;
                }
            }
        }

As for an example test file, you may use any models exported from BlockBench, which uses the "ByPolygon" mapping for normals.

Background info:

This group of issues are discovered when our team is porting OpenFBX library to run natively on C#. Our company is planning to use OpenFBX to expend model loading support for our game (and game engine), as we are currently using block bench parsing and loading only which provides limited features. While the modified C# port is currently closed source and for internal use only, it is undecided whether we will release the port in any format once it is to a stage we are happy with.

nem0 commented 1 year ago

Fixed in 15e70cc00cafbcc0877d674c91b464142c945d30