forked from posecode-dev/posecode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxbot.ts
More file actions
21 lines (19 loc) · 924 Bytes
/
Copy pathxbot.ts
File metadata and controls
21 lines (19 loc) · 924 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/** Node-only loader for the same XBot proportions used by the web playground. */
import { readFileSync } from "node:fs";
import * as THREE from "three";
import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader.js";
import { rigCharacter, type Character, type Proportions } from "posecode-render";
export async function loadXbotCharacter(asset: URL): Promise<Character> {
const bytes = readFileSync(asset);
const buffer = bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength);
const scene = await new Promise<THREE.Object3D>((resolve, reject) => {
new GLTFLoader().parse(buffer, "", (gltf) => resolve(gltf.scene), reject);
});
return rigCharacter(scene);
}
export async function loadXbotProportions(asset: URL): Promise<Proportions> {
const character = await loadXbotCharacter(asset);
const proportions = character.proportions;
character.dispose();
return proportions;
}