Problem with gltf file

Hi,

When exporting a gltf file from Blender as a test case, I get two primitives as shown in the snippet below. However, each primitive refers to the same set of indices. I thought that the indices are global across the same mesh.

When I render each primitive separately, they render ok. I get similar behaviour when rendering more complex models, except the primitives refer to different index buffers, and rendering each primitive separately does not cause any issues.

Has anyone else experienced this issue?

“meshes”:[
{
“name”:“Cube.001”,
“primitives”:[
{
“attributes”:{
“POSITION”:0,
“NORMAL”:1,
“TEXCOORD_0”:2
},
"indices":3,
“material”:0
},
{
“attributes”:{
“POSITION”:4,
“NORMAL”:5,
“TEXCOORD_0”:6
},
"indices":3,
“material”:1
}
]
}
],

If the data in the indices happens to be identical, there is no rule that duplicate copies must be stored. It’s rare for meshes to have different vertex attributes but identical indices, but not invalid. This is a case that glTF implementations are expected to handle.

I take it that you’re either using an engine/viewer, or writing a custom application, in which this doesn’t work? If it’s third-party software, then I would probably file a bug and share a link to the glTF Validator tool to show that the model is valid.

Thanks for your reply. Correct, I’m writing a custom application, and importing the gltf file that I exported via blender.

The solution is to increment the indices by the number of vertices in each primitive, and the model renders correctly. Otherwise, each primitive with its own vertices will have indices that refer to vertices starting at index zero.

Will have to do more testing on other models to see if this works universally.

Hm, that sounds a bit suspicious to me… if the Blender exporter says that both primitives use the same indices then either that’s true — and incrementing the indices would cause problems — or the exporter has a bug. If both primitives have different vertex accessors, why should the first N vertices in one of those accessors be unused? I would check in an online viewer like https://gltf.report/, which uses accessors as-is, to rule out an exporter bug.

Assuming the model looks ok in the viewer, maybe accessor.byteOffset or bufferView.byteOffset is not being applied in your app?

Aside, you may find this VSCode extension helpful to inspect the indices and vertex data directly:

The viewer only says that only the texture coords aren’t used, which is fine. I actually tested incrementing the indices on 3 separate models, where all of them rendered ok.

0 UNUSED_OBJECT This object may be unused. 2 /meshes/0/primitives/0/attributes/TEXCOORD_0
1 UNUSED_OBJECT This object may be unused. 2 /meshes/0/primitives/1/attributes/TEXCOORD_0

None of the accessors in the file don’t have a byteOffset as they point to different bufferView objects

I can’t include links in my post

"accessors":[
	{
		"bufferView":0,
		"componentType":5126,
		"count":24,
		"max":[
			1,
			1,
			1
		],
		"min":[
			-1,
			-1,
			-1
		],
		"type":"VEC3"
	},
	{
		"bufferView":1,
		"componentType":5126,
		"count":24,
		"type":"VEC3"
	},
	{
		"bufferView":2,
		"componentType":5126,
		"count":24,
		"type":"VEC2"
	},
	{
		"bufferView":3,
		"componentType":5123,
		"count":36,
		"type":"SCALAR"
	},
	{
		"bufferView":4,
		"componentType":5126,
		"count":24,
		"max":[
			3.0999999046325684,
			1,
			1
		],
		"min":[
			1.0999999046325684,
			-1,
			-1
		],
		"type":"VEC3"
	},
	{
		"bufferView":5,
		"componentType":5126,
		"count":24,
		"type":"VEC3"
	},
	{
		"bufferView":6,
		"componentType":5126,
		"count":24,
		"type":"VEC2"
	}
],
"bufferViews":[
	{
		"buffer":0,
		"byteLength":288,
		"byteOffset":0,
		"target":34962
	},
	{
		"buffer":0,
		"byteLength":288,
		"byteOffset":288,
		"target":34962
	},
	{
		"buffer":0,
		"byteLength":192,
		"byteOffset":576,
		"target":34962
	},
	{
		"buffer":0,
		"byteLength":72,
		"byteOffset":768,
		"target":34963
	},
	{
		"buffer":0,
		"byteLength":288,
		"byteOffset":840,
		"target":34962
	},
	{
		"buffer":0,
		"byteLength":288,
		"byteOffset":1128,
		"target":34962
	},
	{
		"buffer":0,
		"byteLength":192,
		"byteOffset":1416,
		"target":34962
	}
],

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.