Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gltfpack: hope compressed model reusing attributes and indices bin data as the same as the origin model #726

Closed
rarest opened this issue Jul 23, 2024 · 6 comments

Comments

@rarest
Copy link

rarest commented Jul 23, 2024

As mentioned in 723, in the origin gltf model, mesh[0] and mesh[1] have the same attributes data(buffer index 1, 2, 4, 5) and the same indices data(buffer index 0, 3), only materials are different.

"meshes": [
    {
      "primitives": [
        {
          "attributes": {
            "POSITION": 1,
            "NORMAL": 2
          },
          "indices": 0,
          "material": 0
        },
        {
          "attributes": {
            "POSITION": 4,
            "NORMAL": 5
          },
          "indices": 3,
          "material": 1
        }
      ]
    },
    {
      "primitives": [
        {
          "attributes": {
            "POSITION": 1,
            "NORMAL": 2
          },
          "indices": 0,
          "material": 2
        },
        {
          "attributes": {
            "POSITION": 4,
            "NORMAL": 5
          },
          "indices": 3,
          "material": 3
        }
      ]
    }
  ]

After 724 fix, the scenes informations of meshopt compress model are correct, but the meshes data are not reused, actually attributes and indices bin data of meshes[0] and meshes[1] in the compressed model are repeated. buffer index (0, 1, 2, 3, 4, 5) vs buffer index ( 6, 7, 8, 9, 10, 11) have the same data.

"meshes": [{
	"primitives": [{
		"attributes": {
			"POSITION": 0,
			"NORMAL": 1
		},
		"indices": 2,
		"material": 0
	}, {
		"attributes": {
			"POSITION": 3,
			"NORMAL": 4
		},
		"indices": 5,
		"material": 1
	}]
}, {
	"primitives": [{
		"attributes": {
			"POSITION": 6,
			"NORMAL": 7
		},
		"indices": 8,
		"material": 2
	}, {
		"attributes": {
			"POSITION": 9,
			"NORMAL": 10
		},
		"indices": 11,
		"material": 3
	}]
}]

If vertex attributes and index data can be reused, the model size can be further reduced.
Thanks!

origin.zip
originMeshopt2.zip

@rarest
Copy link
Author

rarest commented Jul 29, 2024

@zeux Could you give me some advice how to share the attributes data between different meshes?

@zeux
Copy link
Owner

zeux commented Jul 29, 2024

gltfpack currently works with mesh attributes independently so the attribute data isn’t shared; doing that for an arbitrary example requires implementing deduplication on an attribute level.

Note that instances like this can be represented using KHR_materials_variants extension; if the input file contains it, gltfpack will correctly preserve it without geometry duplication. For this to work the application would need to use variant switching instead of scene switching as there’s no way to encode “active” variant per scene.

@rarest
Copy link
Author

rarest commented Jul 30, 2024

gltfpack currently works with mesh attributes independently so the attribute data isn’t shared; doing that for an arbitrary example requires implementing deduplication on an attribute level.

Note that instances like this can be represented using KHR_materials_variants extension; if the input file contains it, gltfpack will correctly preserve it without geometry duplication. For this to work the application would need to use variant switching instead of scene switching as there’s no way to encode “active” variant per scene.

Thanks for the valuable advice, I'll look into the KHR_materials_variants extension first。
By the way, is there any plan to support attribute data sharing?

@zeux
Copy link
Owner

zeux commented Jul 30, 2024

By the way, is there any plan to support attribute data sharing?

Not in the short term but it can probably happen in the future.

@rarest rarest closed this as completed Jul 30, 2024
@zeux zeux added the gltfpack label Dec 10, 2024
@zeux
Copy link
Owner

zeux commented Dec 10, 2024

This is properly fixed by #782 I believe (which is part of last gltfpack release).

@rarest
Copy link
Author

rarest commented Dec 11, 2024

nice work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants