vpenades / SharpGLTF

glTF reader and writer for .NET Standard
MIT License
454 stars 72 forks source link

[Question] Mesh Vertex with UVW are exploded #226

Closed mihail-hrushev closed 2 months ago

mihail-hrushev commented 3 months ago

I made a model. Works fine. I need to add UVW coordinates.

To do so - I generate for each vertex about 4 UVW positions.

And works. But when I open my model in blender, and try to edit mesh - it's exploded. Each quad are separated object now.

How to generate quads and "weld" mesh vertexes together?

using VERTEX = SharpGLTF.Geometry.VertexTypes.VertexPosition; .... var mesh = new MeshBuilder<VertexPosition, VertexTexture1>("Beams"); var material = new MaterialBuilder("Black") var prim = mesh.UsePrimitive(material ); .... //For each quad texture coordinates are created individually

void BuildQuad(VERTEX vs1, VERTEX vs2, VERTEX ve1, VERTEX ve2 ,... ) { VertexTexture1 cor1 = new VertexTexture1(new Vector2(WidthAcc, LenghtAcc)); VertexTexture1 cor2 = new VertexTexture1(new Vector2(WidthAcc-WidthFactor, LenghtAcc )); VertexTexture1 cor3 = new VertexTexture1(new Vector2(WidthAcc-WidthFactor, -LengthFactor+LenghtAcc)); VertexTexture1 cor4 = new VertexTexture1(new Vector2(WidthAcc, -LengthFactor+LenghtAcc));

VertexBuilder<VertexPosition, VertexTexture1, VertexEmpty> ver1 =
        new VertexBuilder<VertexPosition, VertexTexture1, VertexEmpty>(vs2, cor2);
    VertexBuilder<VertexPosition, VertexTexture1, VertexEmpty> ver2 =
        new VertexBuilder<VertexPosition, VertexTexture1, VertexEmpty>(vs1, cor1);
    VertexBuilder<VertexPosition, VertexTexture1, VertexEmpty> ver3 =
        new VertexBuilder<VertexPosition, VertexTexture1, VertexEmpty>(ve1, cor4);
    VertexBuilder<VertexPosition, VertexTexture1, VertexEmpty> ver4 =
        new VertexBuilder<VertexPosition, VertexTexture1, VertexEmpty>(ve2, cor3);
prim.AddQuadrangle(ver1, ver2, ver3, ver4);

} // vs1, vs2, ve1, ve2 - are singletons, and reused for neighbor quads. But in the model - it's all - exploded

While with plates, where all of them share same texture coordinate - it works fine

ArchFantasyDome.zip

2024-03-28 17_24_15-Parametric Dome Structrure AR plane rectangulars png ‎- Photos

vpenades commented 3 months ago

This is not a bug. The explanation is quite long, so I'll try to be as short as possible:

glTF is not an authoring format, it's a last mile format, that means that the vertex data is organized for fast rendering and not for easy editing. As a consequence, a vertex that has two adjacent polygons that share the same "vertex position" but have different UV coordinates is effectively duplicated. This is correct and there's no way to solve it from the glTF side.

Since glTF has become quite a standard, people is using it beyond its initial scope, and that's why you're having issues when importing it. I'm not an expert on blender, but the blender importer may have a checkbox to automatically weld vertices on import.

mihail-hrushev commented 3 months ago

Since glTF has become quite a standard, people is using it beyond its initial scope, and that's why you're having issues when importing it. I'm not an expert on blender, but the blender importer may have a checkbox to automatically weld vertices on import.

This is a briliant and clearest explanation! With this context I see a way to work around for that subject. You also right - blender has this import option. Thank you so much!