Comments (9)
@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.
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:
- We should calculate correct min/max in export jobs
- 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.
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.
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.
Hi, do you have idea how to calculate min/max of each mesh in export jobs?
from gltfast.
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.
@IrfanSamuel-aai Can you give example of your code with correct bound calculation?
from gltfast.
@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.
@RAsoftware916 great, thanks for sharing your code.
@atteneder, can this be merged?
from gltfast.
Related Issues (20)
- Exported material through glTFast lose color.
- glTFPbrMetallicRoughness material is not exporting correctly.
- Object type members that are not present in the original JSON have a non-null value
- Change default shader HOT 2
- Editor crashes when importing a glb runtime (URP, Unity 2022, MRTK) HOT 2
- some of the file is missing while importing a glb to unity
- Glb become more mettalic when we switch platform from destop to android
- Install does not work in Unity HOT 3
- Transparency not working when project in compiled
- Has development moved to inside Unity? HOT 5
- KTX spoil mesh texture in Unity build with URP but it works in the editor HOT 2
- Unable to Export from Unity with materials HOT 5
- Meta Quest Browser Failed to import runtime GLBs
- Compile Error occurs when applying "GLTFAST_SAFE" Script Define Symbols HOT 1
- Support for loading large GLB files without copying entire file to managed memory
- How to export the rigged avatar with blendshape using this repo HOT 1
- .glb model exported from 3ds max and cinema4d doesn't import in runtime
- Unable to export draco compressed GLB file at runtime : DracoUnity package needs to be installed HOT 3
- Animation cannot loop when using GltfImport with 'mecanim' settings
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gltfast.