ArrayBuffer -128 instead of 0?

Hi,

my issue regards GLTFLoader.js, and the way a vertice is read in a triangle. My final goal is to make the importer to import animated vertices (not through bones and skinning, nor through ShapeKeys, just plain vertices animation) because it is not supported in Blender (see my question ⚓ T102956 Exporting to GLTF: Can not export keyframes using AnimAll for a single vertice) and also (I guess) in Three.js, but it is useful when you want to visualize structural analysis results from CAE software in C++ memory. :slight_smile:

For the sake of simplicity let as assume that I have a triangle that consists of 3 points, all at 0 (origin).
triangleBuffer.gltf (1.6 KB)

Thus we have
3 points x 3 coordinates x 4 bytes = 36 bytes.

When I console.log the ArrayBuffer for the Vertices of this triangle (L3120 for GLTFLoader.js):

} else {
	console.log(bufferView);
    array = new TypedArray( bufferView, byteOffset, accessorDef.count * itemSize );
}

I am always getting -128 for the 4th byte of the z coordinate instead of 0. See below

Do you know why this happens ? -128 is an alternative of 0 ? Is that a bug of FileReader? It will be better to have 0 for better understanding. :thinking:

Another question is that since each float is 1 byte = 0 up to 255, how an Int8 can be from -255 to 255 ? Where is the ± sign stored? :frowning:

Best, and sorry for the encyclopedic questions,
Dimitrios Ververidis

The range of int8 is [-128, 127].

That said, there are no int8 accessors in the glTF file shared above, or should not be… It’s worth knowing that GLTFLoader does not process the vertex buffer in most cases (exception: sparse accessors, but these are rare). So whatever is in the vertex stream is going directly to the GPU. This means it’s fine to inspect the vertex stream outside of three.js if you want, in tools like https://gltf.report

for (const mesh of document.getRoot().listMeshes()) {
	for (const prim of mesh.listPrimitives()) {
		console.log('indices', prim.getIndices().getArray())		
		console.log('POSITION', prim.getAttribute('POSITION').getArray());
	}
}

Result: