File size: 1,188 Bytes
ea35075
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { PartIndexMappingOfPoseModel } from './defines'

const PosesLibrary: [number, number, number][][] | null = []

function getRandomInt(min: number, max: number) {
    min = Math.ceil(min)
    max = Math.floor(max)
    return Math.floor(Math.random() * (max - min + 1)) + min
}

export function GetRandomPose() {
    if (PosesLibrary)
        return PosesLibrary[getRandomInt(0, PosesLibrary.length - 1)]
    return null
}

export async function LoadPosesLibrary(posesLibraryUrl: string) {
    const response = await fetch(posesLibraryUrl)
    const buffer = await response.arrayBuffer()

    console.log(buffer.byteLength)
    const int16Array = new Int32Array(buffer)

    const num = Object.keys(PartIndexMappingOfPoseModel).length

    for (let i = 0; i < int16Array.length / (num * 3); i++) {
        const temp: [number, number, number][] = []
        for (let j = 0; j < num; j++) {
            const a = int16Array[i * (num * 3) + j * 3 + 0]
            const b = int16Array[i * (num * 3) + j * 3 + 1]
            const c = int16Array[i * (num * 3) + j * 3 + 2]

            temp.push([a / 1000.0, b / 1000.0, c / 1000.0])
        }

        PosesLibrary?.push(temp)
    }
}