T
T
toly192017-05-16 15:05:43
JavaScript
toly19, 2017-05-16 15:05:43

How to convert Uint8Array?

There is data in the form of a Uint8Array array.
c2b9487bb0464f7d93e5e77b212daee8.PNG
Here is the structure:
da447d234fc64df7add1a0a50c6e3bc7.PNG
Here, theoretically, there should be data that is in the picture below:
904059146fb04d7ba24dce246c151274.PNG
How to convert the Uint8Array array to the data in the table ???
PS torn from webgl inspector extension

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaly Stolyarov, 2017-05-16
@toly19

In general, to convert Uint8Array to Float32Array can be done in 2 lines

var uint8array = ...
var point1 = new Float32Array(uint8array.buffer);

where, for example, out of 40 elements (bytes) you get 10 float elements (since Float32 - takes 32 bits == 4 bytes)
for(var i=0;i<uint8array.length;i+=32){  // перебираем элементы каждой записи (строки из последней табл.)

var p1bytes = uint8array.subarray(i,i+12); // получаем данные для первой точки, 12 байт
var p1 = new Float32Array(p1bytes.buffer); // получили 3 элемента float
var p2bytes = uint8array.subarray(i+12,i+20);  // теперь следующие 8 байт
var p2 = new Float32Array(p2bytes.buffer);  // 2 элемента

// дальше идут массивы из элементов по 2 байта (short)

var p3bytes =  uint8array.subarray(i+20,i+24);  
var p3 = new Uint16Array(p1bytes.buffer);

// и т.д.
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question