vpenades / SharpGLTF

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

How to add vertex normals? #145

Closed pigLoveRabbit520 closed 1 year ago

pigLoveRabbit520 commented 2 years ago

I have these properties:

{
    "vertices": 
    [
        {
            "x": -30.91592,
            "y": -2.015286E-06,
            "z": 59.426945
        },
        {
            "x": -37.71443,
            "y": -2.1691449E-10,
            "z": 47.805477
        },
        {
            "x": -40.70887,
            "y": 1.8302139E-06,
            "z": 35.449963
        },
        {
            "x": -28.562584,
            "y": -11.831014,
            "z": 59.42695
        },
        {
            "x": -34.84359,
            "y": -14.432688,
            "z": 47.805477
        },
        {
            "x": -37.61009,
            "y": -15.5786085,
            "z": 35.449963
        },
        ....
    ],
    "faces": 
    [
        80,
        383,
        96,
        96,
        399,
        ...
    ],
    "normals":
    [
        {
            "x": -0.64288884,
            "y": -2.5783203E-07,
            "z": 0.7659595
        },
        {
            "x": -0.68214476,
            "y": -3.768913E-07,
            "z": 0.73121727
        },
        {
            "x": -0.6690719,
            "y": -0.13308686,
            "z": 0.73118436
        },
        {
            "x": -0.6306068,
            "y": -0.12543565,
            "z": 0.7658988
        },
        {
            "x": -0.68214476,
            "y": -3.768913E-07,
            "z": 0.73121727
        },
        {
            "x": -0.77495205,
            "y": -4.8654607E-07,
            "z": 0.63201994
        },
        ...
    ]
}
vpenades commented 2 years ago

You provide no information of what you want to do, no context, just a random file that is totally unrelated to glTF.

So my answer is: look into the unit tests of the project, there's plenty of examples on how to add and use normals.

vpenades commented 1 year ago

Reviewing still open issues, I think I know what you want to do.

You have to create a MeshBuilderobject with VertexPositionNormal vertex structure, and then call multiple times AddTriangle with the vertices. There's plenty of examples in the unit tests.