Giter Site home page Giter Site logo

ACCESSOR_MIN_MISMATCH about gltfast HOT 9 OPEN

IrfanSamuel-aai avatar IrfanSamuel-aai commented on June 11, 2024
ACCESSOR_MIN_MISMATCH

from gltfast.

Comments (9)

RAsoftware916 avatar RAsoftware916 commented on June 11, 2024 1

@IrfanSamuel-aai Thanks for your code. I applied your code to GltfWriter.cs and changed the code in lines from 963 first part of switch. I tested this change on my models which makes errors of min/max mismatch in the validator and after this fix errors didn't appear. `switch (attribute.attribute) {
case VertexAttribute.Position:
Assert.AreEqual(VertexAttributeFormat.Float32,attribute.format);
Assert.AreEqual(3,attribute.dimension);

    int count = uMesh.vertexCount;
    List<Vector3> vertices = new List<Vector3>();
    uMesh.GetVertices(vertices);
    double3 minD = new double3(); 
    double3 maxD = new double3();

    for (int i = 0; i < 3; i++)
    {
        minD[i] = float.MaxValue;
        maxD[i] = float.MinValue;
    }

    for (int i = 0; i < count; i++)
    {
        var v = vertices[i];
        if (v.x < minD[0]) minD[0] = v.x;
        if (v.y < minD[1]) minD[1] = v.y;
        if (v.z < minD[2]) minD[2] = v.z;
        if (v.x > maxD[0]) maxD[0] = v.x;
        if (v.y > maxD[1]) maxD[1] = v.y;
        if (v.z > maxD[2]) maxD[2] = v.z;
    }
    
    accessor.min = new[] {(float)-maxD.x, (float)minD.y, (float)minD.z };
    accessor.max = new[] { (float)-minD.x, (float)maxD.y, (float)maxD.z };
    attributes.POSITION = accessorId;
    break;`

from gltfast.

atteneder avatar atteneder commented on June 11, 2024

Hi @IrfanSamuel-aai,

Thanks for reporting.

The cause of the problem is that the glTF export does not re-calculate the min/max values based on the actual vertex positions (as this requires iterating all vertices), but calculates them from the Mesh's bounds. Those are stored as center/extends vectors and this floating point operation introduces a tiny bit of error, enough to trigger an error by the glTF validator (see issue) and apparently UE's import.

So solutions to solve this:

  1. We should calculate correct min/max in export jobs
  2. UE devs should make their importer less defensive, throw a warning instead of an error, calculate correct values and don't block the import.

from gltfast.

IrfanSamuel-aai avatar IrfanSamuel-aai commented on June 11, 2024

Hi,
Thank you for the reply. Will it be possible to calculate min/max of each mesh in export jobs? We can make this an optional operation to be performed while exporting.
We can't be sure, when UE devs will work on their importer.
Best regards.

from gltfast.

atteneder avatar atteneder commented on June 11, 2024

Hi, Thank you for the reply. Will it be possible to calculate min/max of each mesh in export jobs?

Yes, that's the best approach I think.

from gltfast.

RAsoftware916 avatar RAsoftware916 commented on June 11, 2024

Hi, do you have idea how to calculate min/max of each mesh in export jobs?

from gltfast.

IrfanSamuel-aai avatar IrfanSamuel-aai commented on June 11, 2024

Hi, do you have idea how to calculate min/max of each mesh in export jobs?

Hi, I'm able to correctly calculate the the bounds (double) but only limited by meshBound.SetMinMax( ) as it only accepts Vector3.
@atteneder can provide us an option to pass the min/max for each mesh along with the Export function then the issue can be easily rectified.

from gltfast.

RAsoftware916 avatar RAsoftware916 commented on June 11, 2024

@IrfanSamuel-aai Can you give example of your code with correct bound calculation?

from gltfast.

IrfanSamuel-aai avatar IrfanSamuel-aai commented on June 11, 2024

@RAsoftware916, yes sure :)

public static void GetMeshBounds(Mesh mesh, out double3 min, out double3 max)
{
int count = mesh.vertexCount;
List vertices = new ();
mesh.GetVertices(vertices);

    min = new double3(); 
    max = new double3();

    for (int i = 0; i < 3; i++)
    {
        min[i] = float.MaxValue;
        max[i] = float.MinValue;
    }
    
    for (int i = 0; i < count; i++)
    {
        var v = vertices[i];
        if ((double)v.x < min[0]) min[0] = (double)v.x;
        if ((double)v.y < min[1]) min[1] = (double)v.y;
        if ((double)v.z < min[2]) min[2] = (double)v.z;
        if ((double)v.x > max[0]) max[0] = (double)v.x;
        if ((double)v.y > max[1]) max[1] = (double)v.y;
        if ((double)v.z > max[2]) max[2] = (double)v.z;
    }
}

from gltfast.

IrfanSamuel-aai avatar IrfanSamuel-aai commented on June 11, 2024

@RAsoftware916 great, thanks for sharing your code.
@atteneder, can this be merged?

from gltfast.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.