SOURCE / PINNED RELEASE
Made of little things.
Body Journal
- Release
- e8049f8da4e2…
- Author-recorded commit
- 61c04bf0e8aa…
- License
- LICENSE
- Author’s source reference
- nostr://npub182jczunncwe0jn6frpqwq3e0qjws7yqqnc3auccqv9nte2dnd63scjm4rf/wss%3A%2F%2Fgit.napplet.soy%2F/n-6c4554844c7
Archive hash verified: 4369d778da046a8b…. The source-to-build association is the author’s claim; it has not been independently rebuilt.
export interface SkinMeta {
id: string; vertices: number; triangles: number;
bones: { name: string; parent: number }[];
variants: { gender: number; weight: number }[];
arrays: Record<string, { offset: number; length: number; type: 'H' | 'f' }>;
}
export interface SkinData { meta: SkinMeta; indices: Uint16Array; uvCorners: Float32Array; skinIndices: Uint16Array; skinWeights: Float32Array; positions: Float32Array[]; heads: Float32Array[] }
export const SKIN_MODEL_ID = 'mpfb-skin-1';
export const SKIN_TRIANGLES = 26756;
export function decodeSkin(buffer: ArrayBuffer): SkinData {
const view = new DataView(buffer), decoder = new TextDecoder();
if (decoder.decode(new Uint8Array(buffer, 0, 8)) !== 'BJSKIN01') throw new Error('Unsupported skin asset.');
const length = view.getUint32(8, true), start = 12 + length;
const meta = JSON.parse(decoder.decode(new Uint8Array(buffer, 12, length))) as SkinMeta;
if (meta.id !== SKIN_MODEL_ID || meta.triangles !== SKIN_TRIANGLES || meta.bones.length !== 53 || meta.variants.length !== 9) throw new Error('Skin version mismatch.');
const array = (name: string) => {
const a = meta.arrays[name];
return a.type === 'H' ? new Uint16Array(buffer, start+a.offset,a.length) : new Float32Array(buffer,start+a.offset,a.length);
};
return { meta, indices: array('indices') as Uint16Array, uvCorners: array('uvCorners') as Float32Array, skinIndices: array('skinIndices') as Uint16Array, skinWeights: array('skinWeights') as Float32Array, positions: Array.from({length:9},(_,i)=>array(`positions${i}`) as Float32Array), heads: Array.from({length:9},(_,i)=>array(`heads${i}`) as Float32Array) };
}
// Bilinear interpolation between real shape samples. These are visual controls,
// not predictions of an individual's anatomy from sex, height or weight.
export function shapeWeights(gender: number, weight: number): number[] {
const g = Math.max(0,Math.min(1,gender))*2, w = Math.max(0,Math.min(1,weight))*2;
const result = Array<number>(9).fill(0);
for (let i=0;i<3;i++) for (let j=0;j<3;j++) result[i*3+j]=Math.max(0,1-Math.abs(g-i))*Math.max(0,1-Math.abs(w-j));
return result;
}
