[英]How to build Float32Array from ArrayBuffer
Consider I have an ArrayBuffer, as shown in next screenshot)考虑我有一个 ArrayBuffer,如下一个屏幕截图所示)
//recompute object from vertices and normals
const verticesBuffer:ArrayBuffer = e.data.verticesBufferArray;
const normalsBuffer:ArrayBuffer = e.data.normalsBufferArray;
const vertices = new Float32Array(verticesBuffer);
const normals = new Float32Array(normalsBuffer);
But at this point vertices and normals are undefined.但此时顶点和法线是未定义的。 So, variables vertices and normals are undefined while verticesBuffer and normalBuffer are ok.
因此,变量 vertices 和 normals 是未定义的,而 verticesBuffer 和 normalBuffer 是可以的。
On the conversion I get following error在转换时,我收到以下错误
const vertices = new Float32Array(verticesBuffer);
Uncaught RangeError: Invalid typed array length: 39744
未捕获的 RangeError:无效的类型化数组长度:39744
So question is how to pass from verticesBuffer:ArrayBuffer to vertices:Float32Array ?所以问题是如何从 verticesBuffer:ArrayBuffer 传递到 vertices:Float32Array ?
Thanks!谢谢!
const vertexCount = verticesBuffer.byteLength / 4;
const normalCount = normalsBuffer.byteLength / 4;
const vertices = Float32Array.from(verticesBuffer, 0, vertexCount);
const normals = Float32Array.from(normalsBuffer, 0, normalCount);
Consider I have an ArrayBuffer, as shown in next screenshot)考虑我有一个ArrayBuffer,如下面的屏幕截图所示)
//recompute object from vertices and normals
const verticesBuffer:ArrayBuffer = e.data.verticesBufferArray;
const normalsBuffer:ArrayBuffer = e.data.normalsBufferArray;
const vertices = new Float32Array(verticesBuffer);
const normals = new Float32Array(normalsBuffer);
But at this point vertices and normals are undefined.但是在这一点上,顶点和法线是不确定的。 So, variables vertices and normals are undefined while verticesBuffer and normalBuffer are ok.
因此,未定义变量vertices和法线,而verticesBuffer和normalBuffer正常。
On the conversion I get following error转换时出现以下错误
const vertices = new Float32Array(verticesBuffer);
Uncaught RangeError: Invalid typed array length: 39744
未捕获的RangeError:无效的类型化数组长度:39744
So question is how to pass from verticesBuffer:ArrayBuffer to vertices:Float32Array ?那么问题是如何从verticesBuffer:ArrayBuffer传递到vertices:Float32Array?
Thanks!谢谢!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.