GitHub bc0a618 Merge pull request #5 from MIINGIJANG/claude/sweet-archimedes-rzww8l
Browse files- web/models/avatar.json +30 -2
- web/rig.js +42 -0
web/models/avatar.json
CHANGED
|
@@ -1,9 +1,37 @@
|
|
| 1 |
{
|
| 2 |
-
"about": "avatar.glb 설정 (web/rig.js·avatar.js). bones: 뼈 이름이 자동 인식되지 않을 때 {\"leftUpperArm\": \"뼈 이름\"} 처럼 지정. clothes: 옷 재질 이름 정규식, clothTint: 옷 색에 곱할 색(false 면 그대로), hat: false 면 안전모 안 씌움(모델에 안전모가 있을 때), roughness: 숫자면 모든 재질을 그 거칠기로(광택 맵 무시, 비닐처럼 번들거릴 때), torsoScale: 상체 길이 비율(척추 마디 간격), frameBottom: 화면 아래 끝 = 골반 + 이 값(m)",
|
| 3 |
"bones": {},
|
| 4 |
"clothTint": false,
|
| 5 |
"hat": false,
|
| 6 |
"roughness": 0.78,
|
| 7 |
"torsoScale": 0.9,
|
| 8 |
-
"frameBottom": 0.12
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
}
|
|
|
|
| 1 |
{
|
| 2 |
+
"about": "avatar.glb 설정 (web/rig.js·avatar.js). bones: 뼈 이름이 자동 인식되지 않을 때 {\"leftUpperArm\": \"뼈 이름\"} 처럼 지정. clothes: 옷 재질 이름 정규식, clothTint: 옷 색에 곱할 색(false 면 그대로), hat: false 면 안전모 안 씌움(모델에 안전모가 있을 때), roughness: 숫자면 모든 재질을 그 거칠기로(광택 맵 무시, 비닐처럼 번들거릴 때), torsoScale: 상체 길이 비율(척추 마디 간격), frameBottom: 화면 아래 끝 = 골반 + 이 값(m), physique: 체격 배율 [가로,세로,앞뒤] (waist·chest·neck·upperArm·forearm, shoulders 는 어깨 너비 배율)",
|
| 3 |
"bones": {},
|
| 4 |
"clothTint": false,
|
| 5 |
"hat": false,
|
| 6 |
"roughness": 0.78,
|
| 7 |
"torsoScale": 0.9,
|
| 8 |
+
"frameBottom": 0.12,
|
| 9 |
+
"physique": {
|
| 10 |
+
"waist": [
|
| 11 |
+
1.06,
|
| 12 |
+
1,
|
| 13 |
+
1.06
|
| 14 |
+
],
|
| 15 |
+
"chest": [
|
| 16 |
+
1.08,
|
| 17 |
+
1,
|
| 18 |
+
1.06
|
| 19 |
+
],
|
| 20 |
+
"neck": [
|
| 21 |
+
1.12,
|
| 22 |
+
1,
|
| 23 |
+
1.1
|
| 24 |
+
],
|
| 25 |
+
"shoulders": 1.1,
|
| 26 |
+
"upperArm": [
|
| 27 |
+
1,
|
| 28 |
+
1.14,
|
| 29 |
+
1.14
|
| 30 |
+
],
|
| 31 |
+
"forearm": [
|
| 32 |
+
1,
|
| 33 |
+
1.1,
|
| 34 |
+
1.1
|
| 35 |
+
]
|
| 36 |
+
}
|
| 37 |
}
|
web/rig.js
CHANGED
|
@@ -82,6 +82,47 @@ export function findTwistBones(root) {
|
|
| 82 |
return res;
|
| 83 |
}
|
| 84 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
// GLB 를 VRM 비슷한 객체로: { scene, humanoid, update(dt) }
|
| 86 |
export function buildRig(gltf, config = {}) {
|
| 87 |
const scene = gltf.scene;
|
|
@@ -95,6 +136,7 @@ export function buildRig(gltf, config = {}) {
|
|
| 95 |
const need = ["hips", "spine", "head", "leftUpperArm", "leftLowerArm", "leftHand", "rightUpperArm", "rightLowerArm", "rightHand"];
|
| 96 |
const missing = need.filter((n) => !bones[n]);
|
| 97 |
if (missing.length) throw new Error("아바타 뼈를 찾지 못함: " + missing.join(", ") + " (web/models/avatar.json 의 bones 로 지정)");
|
|
|
|
| 98 |
// 상체 비율: config.torsoScale (예: 0.9) 이면 척추 마디 사이 간격을 그만큼 줄임 (뼈를 따라 몸통 메시도 줄어듦)
|
| 99 |
if (config.torsoScale && config.torsoScale !== 1) {
|
| 100 |
for (const n of ["chest", "upperChest", "neck"]) if (bones[n]) bones[n].position.multiplyScalar(config.torsoScale);
|
|
|
|
| 82 |
return res;
|
| 83 |
}
|
| 84 |
|
| 85 |
+
// 체격 조절 (config.physique): 뼈 크기를 바꿔 몸 메시도 함께 커지게. 값은 화면 기준 [가로(x), 세로(y), 앞뒤(z)] 배율
|
| 86 |
+
// waist: 허리, chest: 가슴(허리 배율에 곱해짐), neck: 목 굵기, shoulders: 어깨 너비(쇄골 길이), upperArm·forearm: 팔 굵기
|
| 87 |
+
// 자식 뼈는 크기를 이어받으므로, 커지면 안 되는 곳(목 위·팔 아래)은 반대로 줄여 원래 크기로 되돌림
|
| 88 |
+
// (기본 자세에서 뼈 축이 화면 축과 거의 나란하다고 보고, 뼈의 로컬 축마다 가장 가까운 화면 축의 배율을 씀)
|
| 89 |
+
function applyPhysique(bones, P, scene) {
|
| 90 |
+
scene.updateMatrixWorld(true);
|
| 91 |
+
const V3 = (a) => new THREE.Vector3(...(Array.isArray(a) ? a : [a, a, a]));
|
| 92 |
+
const quat = new Map();
|
| 93 |
+
for (const b of Object.values(bones)) quat.set(b, b.getWorldQuaternion(new THREE.Quaternion()));
|
| 94 |
+
const toLocal = (bone, w) => {
|
| 95 |
+
const q = quat.get(bone), out = new THREE.Vector3();
|
| 96 |
+
["x", "y", "z"].forEach((ax, i) => {
|
| 97 |
+
const d = new THREE.Vector3(i === 0 ? 1 : 0, i === 1 ? 1 : 0, i === 2 ? 1 : 0).applyQuaternion(q);
|
| 98 |
+
const a = [Math.abs(d.x), Math.abs(d.y), Math.abs(d.z)];
|
| 99 |
+
out[ax] = [w.x, w.y, w.z][a.indexOf(Math.max(...a))];
|
| 100 |
+
});
|
| 101 |
+
return out;
|
| 102 |
+
};
|
| 103 |
+
const mul = (bone, w) => { if (bone) bone.scale.multiply(toLocal(bone, w)); };
|
| 104 |
+
const inv = (w) => new THREE.Vector3(1 / w.x, 1 / w.y, 1 / w.z);
|
| 105 |
+
const waist = V3(P.waist || 1), chest = V3(P.chest || 1), neck = V3(P.neck || 1);
|
| 106 |
+
const trunk = waist.clone().multiply(chest);
|
| 107 |
+
mul(bones.spine, waist);
|
| 108 |
+
mul(bones.chest || bones.upperChest, chest);
|
| 109 |
+
// 목: 몸통 배율을 되돌린 뒤 목 굵기만. 머리는 목 배율도 되돌림
|
| 110 |
+
mul(bones.neck, inv(trunk).multiply(neck));
|
| 111 |
+
mul(bones.head, inv(neck));
|
| 112 |
+
const neckCarries = bones.leftShoulder && bones.leftShoulder.parent === bones.neck;
|
| 113 |
+
for (const side of ["left", "right"]) {
|
| 114 |
+
const sh = bones[side + "Shoulder"], up = bones[side + "UpperArm"], lo = bones[side + "LowerArm"], hand = bones[side + "Hand"];
|
| 115 |
+
if (sh && !neckCarries) mul(sh, inv(trunk)); // 쇄골이 가슴에 붙은 뼈대: 몸통 배율 되돌림
|
| 116 |
+
else if (sh) mul(sh, inv(neck)); // 쇄골이 목에 붙은 뼈대(Biped): 목 배율 되돌림
|
| 117 |
+
if (up && P.shoulders) up.position.multiplyScalar(P.shoulders); // 어깨 너비
|
| 118 |
+
const ua = V3(P.upperArm || 1), fa = V3(P.forearm || 1);
|
| 119 |
+
mul(up, ua);
|
| 120 |
+
mul(lo, inv(ua).multiply(fa));
|
| 121 |
+
mul(hand, inv(fa));
|
| 122 |
+
}
|
| 123 |
+
scene.updateMatrixWorld(true);
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
// GLB 를 VRM 비슷한 객체로: { scene, humanoid, update(dt) }
|
| 127 |
export function buildRig(gltf, config = {}) {
|
| 128 |
const scene = gltf.scene;
|
|
|
|
| 136 |
const need = ["hips", "spine", "head", "leftUpperArm", "leftLowerArm", "leftHand", "rightUpperArm", "rightLowerArm", "rightHand"];
|
| 137 |
const missing = need.filter((n) => !bones[n]);
|
| 138 |
if (missing.length) throw new Error("아바타 뼈를 찾지 못함: " + missing.join(", ") + " (web/models/avatar.json 의 bones 로 지정)");
|
| 139 |
+
if (config.physique) applyPhysique(bones, config.physique, scene);
|
| 140 |
// 상체 비율: config.torsoScale (예: 0.9) 이면 척추 마디 사이 간격을 그만큼 줄임 (뼈를 따라 몸통 메시도 줄어듦)
|
| 141 |
if (config.torsoScale && config.torsoScale !== 1) {
|
| 142 |
for (const n of ["chest", "upperChest", "neck"]) if (bones[n]) bones[n].position.multiplyScalar(config.torsoScale);
|