Can Mesh hold SharedArrayBuffer?

Hi everyone,

Quick question: will sth like this work:

	//Create a custom mesh  
	var customMesh = new BABYLON.Mesh("custom", scene);

	//Set arrays for positions and indices
	var positions = [-5, 2, -3, -7, -2, -3, -3, -2, -3, 5, 2, 3, 7, -2, 3, 3, -2, 3]; //Float32Array
	var indices = [0, 1, 2, 3, 4, 5];

	const spos = new SharedArrayBuffer(positions.length * 32);

	//Create a vertexData object
	var vertexData = new BABYLON.VertexData();

	//Assign positions and indices to vertexData
	vertexData.positions = spos;
	vertexData.indices = indices;	

	//Apply vertexData to custom mesh
	vertexData.applyToMesh(customMesh);

Will using SharedArrayBuffer work at all here and/or cause a recreation of the data as Float32Array?

Best wishes
Joe

yep, this works. wrap the sharedarraybuffer in a Float32Array yourself and hand it to setVerticesData, babylon keeps the reference as is and uploads it straight to the gpu, webgl has no problem with sab-backed views. just make sure the page is cross-origin isolated or SharedArrayBuffer wont exist at all. if youre mutating it from a worker, create the buffer as updatable and call updateVerticesData after writes, the gpu copy wont see the changes on its own.

Ah, thanks! :slight_smile:

Double thanks :smiley: