vpenades / SharpGLTF

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

GLB file shows incorrect logical nodes #117

Closed TechAspirant closed 2 years ago

TechAspirant commented 2 years ago

Hello,

In my case the glb file is showing incorrect number of logical nodes. But its rightly loaded in babylonjs sandbox. Below is the link of glb file and code for reference https://nsimagefolder.s3.us-east-2.amazonaws.com/optima.glb

SharpGLTF.Schema2.ReadSettings readSettings = new SharpGLTF.Schema2.ReadSettings();
readSettings.Validation = SharpGLTF.Validation.ValidationMode.Skip;
var model = SharpGLTF.Schema2.ModelRoot.Load(@"E:\Source\3DTools\3Dglbfiles\myfile.glb", readSettings);
var logicalNodes = model.LogicalNodes;
vpenades commented 2 years ago

hmm... which number do you get, and which number do you expect?

Notice that there's Logical Nodes and Visual Nodes

model.LogicalNodes is the flattened list of nodes as they're stored within the model, regardless of whether they're being used in a scene or not.

model.DefaultScene.VisualChildren is the nodes actually visible in the scene.

TechAspirant commented 2 years ago

I am getting logical node count as 4. But If I see in sandbox provided by babylon I can see some child nodes which are misssing when I read from the SharpGLTF. image

vpenades commented 2 years ago

These doesn't look like nodes, they seem to be Mesh Primitives, which are contained within a Mesh in LogicalMeshes

TechAspirant commented 2 years ago

Other files are loaded correctly. Except the shared one. Logical Meshes count is only 2. I am looking for all children in 'TestFuerJochen' Node.

vpenades commented 2 years ago

The "optima" model you attached only has 4 logical nodes inside, this is the relevant section of the code:

"nodes": [
    {
      "name": "Cube",
      "mesh": 0
    },
    {
      "name": "Light",
      "rotation": [
        0.169075757,
        0.755880356,
        -0.272171378,
        0.570947528
      ],
      "translation": [
        4.07624531,
        5.903862,
        -1.00545394
      ]
    },
    {
      "name": "Camera",
      "rotation": [
        0.483536035,
        0.336871594,
        -0.208703607,
        0.780482709
      ],
      "translation": [
        7.35889149,
        4.95830917,
        6.92579079
      ]
    },
    {
      "name": "TestFuerJochen",
      "mesh": 1,
      "rotation": [
        0.707106829,
        0,
        0,
        0.707106709
      ]
    }
  ]

It defines TWO meshes, which might be located in LogicalMeshes

"meshes": [
    {
      "name": "Cube",
      "primitives": [
        {
          "attributes": {
            "POSITION": 0,
            "NORMAL": 1,
            "TEXCOORD_0": 2
          },
          "indices": 3,
          "material": 0
        }
      ]
    },
    {
      "name": "TestFuerJochen",
      "primitives": [
        {
          "attributes": {
            "POSITION": 4,
            "NORMAL": 5
          },
          "indices": 6,
          "material": 1
        },
        {
          "attributes": {
            "POSITION": 7,
            "NORMAL": 8
          },
          "indices": 9,
          "material": 2
        },
        {
          "attributes": {
            "POSITION": 10,
            "NORMAL": 11
          },
          "indices": 12,
          "material": 3
        },
        {
          "attributes": {
            "POSITION": 13,
            "NORMAL": 14
          },
          "indices": 15,
          "material": 4
        },
        , 
        ,
        ,
        ,
        ,

So the first mesh is just a cube, and the SECOND MESH, has +200 primitices, which is where all the geometry "nodes" are located.

TechAspirant commented 2 years ago

Whats the primitive name in this case ? Does that mean I have to check that a mesh contains primitive or not and If it does read the primitive information as well.

vpenades commented 2 years ago

Yes, mesh primitives is where the geometry is stored

TechAspirant commented 2 years ago

Do primitive follow a naming convention Say MeshName_Primitive ?

vpenades commented 2 years ago

No, primitives are just rendering batches within a mesh

TechAspirant commented 2 years ago

If so than why it gets highlighted as a specific part in the babylon sandbox ?

vpenades commented 2 years ago

Why Babylon chose to display the data in the way they did is a question for Babylon.

What I do know is the GLB model you attached has 4 nodes and 2 meshes, and the 2nd mesh has +200 primitives