Failed to load glb file

Hello, All.

I’m testing loading several glb file via playcanvas viewer and somehow certain glb files are unable to be loaded.

react_devtools_backend.js:2430 Error loading model: 52910G9610.glb [TypeError: Cannot read property 'count' of undefined]

The error message is the above.

and below is the code from playcanvas.mjs and the problematic line is var numVertices = positionDesc.count;

var createVertexBufferInternal = function createVertexBufferInternal(device, sourceDesc, disableFlipV) {
	var positionDesc = sourceDesc[SEMANTIC_POSITION];
	var numVertices = positionDesc.count;
	var vertexDesc = [];

	for (var semantic in sourceDesc) {
		if (sourceDesc.hasOwnProperty(semantic)) {
			vertexDesc.push({
				semantic: semantic,
				components: sourceDesc[semantic].components,
				type: sourceDesc[semantic].type,
				normalize: !!sourceDesc[semantic].normalize
			});
		}
	}

	var elementOrder = [SEMANTIC_POSITION, SEMANTIC_NORMAL, SEMANTIC_TANGENT, SEMANTIC_COLOR, SEMANTIC_BLENDINDICES, SEMANTIC_BLENDWEIGHT, SEMANTIC_TEXCOORD0, SEMANTIC_TEXCOORD1];
	vertexDesc.sort(function (lhs, rhs) {
		var lhsOrder = elementOrder.indexOf(lhs.semantic);
		var rhsOrder = elementOrder.indexOf(rhs.semantic);
		return lhsOrder < rhsOrder ? -1 : rhsOrder < lhsOrder ? 1 : 0;
	});
	var i, j, k;
	var source, target, sourceOffset;
	var vertexFormat = new VertexFormat(device, vertexDesc);
	var isCorrectlyInterleaved = true;

	for (i = 0; i < vertexFormat.elements.length; ++i) {
		target = vertexFormat.elements[i];
		source = sourceDesc[target.name];
		sourceOffset = source.offset - positionDesc.offset;

		if (source.buffer !== positionDesc.buffer || source.stride !== target.stride || source.size !== target.size || sourceOffset !== target.offset) {
			isCorrectlyInterleaved = false;
			break;
		}
	}

	var vertexBuffer = new VertexBuffer(device, vertexFormat, numVertices, BUFFER_STATIC);
	var vertexData = vertexBuffer.lock();
	var targetArray = new Uint32Array(vertexData);
	var sourceArray;

	if (isCorrectlyInterleaved) {
		sourceArray = new Uint32Array(positionDesc.buffer, positionDesc.offset, numVertices * vertexBuffer.format.size / 4);
		targetArray.set(sourceArray);
	} else {
		var targetStride, sourceStride;

		for (i = 0; i < vertexBuffer.format.elements.length; ++i) {
			target = vertexBuffer.format.elements[i];
			targetStride = target.stride / 4;
			source = sourceDesc[target.name];
			sourceArray = new Uint32Array(source.buffer, source.offset, source.count * source.stride / 4);
			sourceStride = source.stride / 4;
			var src = 0;
			var dst = target.offset / 4;
			var kend = Math.floor((source.size + 3) / 4);

			for (j = 0; j < numVertices; ++j) {
				for (k = 0; k < kend; ++k) {
					targetArray[dst + k] = sourceArray[src + k];
				}

				src += sourceStride;
				dst += targetStride;
			}
		}
	}

	if (!disableFlipV) {
		flipTexCoordVs(vertexBuffer);
	}

	vertexBuffer.unlock();
	return vertexBuffer;
};

I’ve used FBX2GLTF to convert fbx to glb.

Is there any option I must use to convert?

@slimbuck, one for you?

@sooyong_Kim Does the GLB work with other viewers (eg https://sandbox.babylonjs.com/)

yes it works on babylonjs sandbox.

I can share glb files via email. :slight_smile:

We were testing a lot with FBX2GLTF with the default options, so perhaps just some bug in our loader. If you can share the glb (with @yaustar), please do so and we’ll investigate.

Can you kindly share the email address?

Can you email support@playcanvas.com please?

Just emailed them. :slight_smile:

Thanks, we’ve raised an internal ticket to look at these :slight_smile:

We are currently investigating. It looks like there are no mesh positions in the vertex buffers which seems odd :thinking:

If you need, I can also share gltf versions of those part. Somehow they are working file if we convert them as gltf.

Would you have fbx version of it you could share?

Those files are at my work PC. I will share them tomorrow :slight_smile:

1 Like

@sooyong_Kim Martin has fixed the issue the GLB with no position data in this PR: https://github.com/playcanvas/engine/pull/2965

This should be deployed out in the engine release this/next week. :slight_smile: