From 2dd5e588c58bd50a5e09c1188bc1b89a2adac331 Mon Sep 17 00:00:00 2001
From: H3l!0s_T3k <90980178+Ismail-Benali@users.noreply.github.com>
Date: Wed, 4 Nov 2026 21:14:19 +0000
Subject: [PATCH 06/29] Fix character import document variable shadowing
---
app.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/app.js b/app.js
index 8755240..bf44768 100644
--- a/app.js
+++ b/app.js
@@ -140,7 +140,7 @@ animate();
document.getElementById('loading').classList.add('hidden');
function update(){build();persistLook()}
function persistLook(){try{localStorage.setItem(STORAGE_KEY,JSON.stringify(validateAvatarConfig(state)))}catch(error){console.warn('Unable to save persona locally:',error)}}
-function restoreLook(input){try{const document=validateCharacterDocument(input);Object.assign(state,document.config);const selector=document.getElementById('characterPreset');if(selector)selector.value=document.profile?.id||'';syncControls();update();toast(document.profile?'تم استيراد ملف الشخصية':'تمت استعادة الإطلالة')}catch(error){toast('ملف الشخصية غير صالح أو غير مدعوم');console.error(error)}}
+function restoreLook(input){try{const characterDocument=validateCharacterDocument(input);Object.assign(state,characterDocument.config);const selector=globalThis.document.getElementById('characterPreset');if(selector)selector.value=characterDocument.profile?.id||'';syncControls();update();toast(characterDocument.profile?'تم استيراد ملف الشخصية':'تمت استعادة الإطلالة')}catch(error){toast('ملف الشخصية غير صالح أو غير مدعوم');console.error(error)}}
function syncControls(){
const keys={skin:'skinOptions',hair:'hairOptions',cloth:'clothOptions'};
for(const [key,id] of Object.entries(keys))document.querySelectorAll(`#${id} .swatch`).forEach(b=>b.classList.toggle('selected',b.dataset.value===state[key]));
From c23008380f70c2b8cb2e2d86387d8b5fb3fedb85 Mon Sep 17 00:00:00 2001
From: H3l!0s_T3k <90980178+Ismail-Benali@users.noreply.github.com>
Date: Wed, 4 Nov 2026 21:32:32 +0000
Subject: [PATCH 07/29] Expand versioned character design schema
---
src/avatar-config.js | 106 ++++++++++++++++++++++++++++++-------------
1 file changed, 74 insertions(+), 32 deletions(-)
diff --git a/src/avatar-config.js b/src/avatar-config.js
index ec8a506..951e831 100644
--- a/src/avatar-config.js
+++ b/src/avatar-config.js
@@ -1,9 +1,8 @@
/**
- * Versioned, platform-neutral avatar configuration contract.
- * Keep this module free of rendering dependencies so it can be reused by
- * future web, mobile, and server-side adapters.
+ * Versioned, renderer-independent character design contract.
+ * Version 1 flat looks are migrated automatically to the nested version 2 model.
*/
-export const AVATAR_CONFIG_VERSION = 1;
+export const AVATAR_CONFIG_VERSION = 2;
export const AVATAR_OPTIONS = Object.freeze({
hairStyle: ['short', 'curly', 'long', 'shaved'],
@@ -13,6 +12,26 @@ export const AVATAR_OPTIONS = Object.freeze({
accessory: ['none', 'glasses', 'earring', 'scarf']
});
+export const DESIGN_DEFAULTS = Object.freeze({
+ body: Object.freeze({
+ height: 1, shoulderWidth: 1, torsoLength: 1, bodyDepth: 1,
+ waistWidth: 1, hipWidth: 1, armLength: 1, legLength: 1, headScale: 1, neckLength: 1
+ }),
+ face: Object.freeze({
+ shape: 'oval', width: 1, height: 1, cheekboneWidth: 1, jawWidth: 1,
+ chinWidth: 1, noseBridgeHeight: 1, noseLength: 1, noseWidth: 1,
+ noseTip: 1, earSize: 1, earProtrusion: 1, earAngle: 0
+ }),
+ hairDetails: Object.freeze({
+ volume: 1, density: 1, fringe: 0.25, part: 'center',
+ curl: 0.5, sideburn: 0.5, length: 1
+ }),
+ clothing: Object.freeze({
+ fit: 'regular', sleeveLength: 1, robeLength: 1, collarHeight: 1,
+ embroidery: 0.65, trimColor: '#c7a45e', belt: false, layer: 'single'
+ })
+});
+
export const DEFAULT_AVATAR_CONFIG = Object.freeze({
schemaVersion: AVATAR_CONFIG_VERSION,
skin: '#b97850',
@@ -23,42 +42,65 @@ export const DEFAULT_AVATAR_CONFIG = Object.freeze({
headwear: 'none',
expression: 'smile',
eyes: '#38251e',
- accessory: 'none'
+ accessory: 'none',
+ ...DESIGN_DEFAULTS
});
const HEX_COLOR = /^#[0-9a-fA-F]{6}$/;
+const ENUMS = {
+ 'face.shape': ['oval', 'round', 'square', 'heart', 'long'],
+ 'hairDetails.part': ['center', 'left', 'right', 'none'],
+ 'clothing.fit': ['slim', 'regular', 'loose', 'oversized'],
+ 'clothing.layer': ['single', 'inner-outer', 'ceremonial']
+};
+const RANGES = {
+ 'body.height':[0.8,1.2], 'body.shoulderWidth':[0.7,1.35], 'body.torsoLength':[0.8,1.2],
+ 'body.bodyDepth':[0.75,1.3], 'body.waistWidth':[0.7,1.35], 'body.hipWidth':[0.7,1.4],
+ 'body.armLength':[0.8,1.2], 'body.legLength':[0.8,1.2], 'body.headScale':[0.8,1.2],
+ 'body.neckLength':[0.7,1.3], 'face.width':[0.75,1.25], 'face.height':[0.8,1.2],
+ 'face.cheekboneWidth':[0.75,1.3], 'face.jawWidth':[0.7,1.3], 'face.chinWidth':[0.65,1.35],
+ 'face.noseBridgeHeight':[0.65,1.35], 'face.noseLength':[0.7,1.3], 'face.noseWidth':[0.65,1.35],
+ 'face.noseTip':[0.7,1.3], 'face.earSize':[0.7,1.3], 'face.earProtrusion':[0.5,1.5],
+ 'face.earAngle':[-25,25], 'hairDetails.volume':[0.5,1.6], 'hairDetails.density':[0.5,1.5],
+ 'hairDetails.fringe':[0,1], 'hairDetails.curl':[0,1], 'hairDetails.sideburn':[0,1],
+ 'hairDetails.length':[0.5,1.8], 'clothing.sleeveLength':[0.5,1.3],
+ 'clothing.robeLength':[0.7,1.3], 'clothing.collarHeight':[0.5,1.5],
+ 'clothing.embroidery':[0,1]
+};
-/**
- * Validates a serialized avatar look. Returns a normalized copy or throws
- * a descriptive TypeError. Unknown keys are rejected to keep the contract
- * explicit and safe to persist.
- */
-export function validateAvatarConfig(input) {
- if (!input || typeof input !== 'object' || Array.isArray(input)) {
- throw new TypeError('Avatar config must be an object.');
- }
+function mergeDesign(source = {}) {
+ if (!source || typeof source !== 'object' || Array.isArray(source)) throw new TypeError('Design section must be an object.');
+ return Object.fromEntries(Object.entries(DESIGN_DEFAULTS).map(([section, defaults]) => {
+ const supplied = source[section] ?? {};
+ if (!supplied || typeof supplied !== 'object' || Array.isArray(supplied)) throw new TypeError(`Invalid ${section} design section.`);
+ for (const key of Object.keys(supplied)) if (!(key in defaults)) throw new TypeError(`Unknown design property: ${section}.${key}`);
+ return [section, { ...defaults, ...supplied }];
+ }));
+}
+export function validateAvatarConfig(input) {
+ if (!input || typeof input !== 'object' || Array.isArray(input)) throw new TypeError('Avatar config must be an object.');
const allowedKeys = new Set(Object.keys(DEFAULT_AVATAR_CONFIG));
- for (const key of Object.keys(input)) {
- if (!allowedKeys.has(key)) throw new TypeError(`Unknown avatar property: ${key}`);
- }
-
- const value = { ...DEFAULT_AVATAR_CONFIG, ...input };
- if (value.schemaVersion !== AVATAR_CONFIG_VERSION) {
- throw new TypeError('Unsupported avatar config schema version.');
+ for (const key of Object.keys(input)) if (!allowedKeys.has(key)) throw new TypeError(`Unknown avatar property: ${key}`);
+ const version = input.schemaVersion ?? 1;
+ if (version !== 1 && version !== AVATAR_CONFIG_VERSION) throw new TypeError('Unsupported avatar config schema version.');
+ const value = { ...DEFAULT_AVATAR_CONFIG, ...input, schemaVersion: AVATAR_CONFIG_VERSION };
+ for (const key of ['skin','hair','cloth','eyes']) {
+ if (typeof value[key] !== 'string' || !HEX_COLOR.test(value[key])) throw new TypeError(`Invalid color value for ${key}.`);
}
+ for (const [key, choices] of Object.entries(AVATAR_OPTIONS)) if (!choices.includes(value[key])) throw new TypeError(`Unsupported ${key} value.`);
- for (const key of ['skin', 'hair', 'cloth', 'eyes']) {
- if (typeof value[key] !== 'string' || !HEX_COLOR.test(value[key])) {
- throw new TypeError(`Invalid color value for ${key}.`);
+ const design = mergeDesign(input);
+ for (const [section, values] of Object.entries(design)) {
+ for (const [key, item] of Object.entries(values)) {
+ const path = `${section}.${key}`;
+ if (ENUMS[path] && !ENUMS[path].includes(item)) throw new TypeError(`Unsupported ${path} value.`);
+ if (RANGES[path] && (typeof item !== 'number' || !Number.isFinite(item) || item < RANGES[path][0] || item > RANGES[path][1])) {
+ throw new TypeError(`Invalid ${path} value; expected ${RANGES[path].join('..')}.`);
+ }
+ if (path === 'clothing.trimColor' && (typeof item !== 'string' || !HEX_COLOR.test(item))) throw new TypeError('Invalid clothing.trimColor value.');
+ if (path === 'clothing.belt' && typeof item !== 'boolean') throw new TypeError('Invalid clothing.belt value.');
}
}
-
- for (const [key, choices] of Object.entries(AVATAR_OPTIONS)) {
- if (!choices.includes(value[key])) {
- throw new TypeError(`Unsupported ${key} value.`);
- }
- }
-
- return Object.freeze(value);
+ return Object.freeze({ ...value, ...Object.fromEntries(Object.entries(design).map(([key, section]) => [key, Object.freeze(section)])) });
}
From 6130b3b50395cd065e5b617755d738044ff094d2 Mon Sep 17 00:00:00 2001
From: H3l!0s_T3k <90980178+Ismail-Benali@users.noreply.github.com>
Date: Wed, 4 Nov 2026 21:32:34 +0000
Subject: [PATCH 08/29] Support version 2 character documents
---
src/character-library.js | 30 +++++++++---------------------
1 file changed, 9 insertions(+), 21 deletions(-)
diff --git a/src/character-library.js b/src/character-library.js
index 65a0d76..bcee0ba 100644
--- a/src/character-library.js
+++ b/src/character-library.js
@@ -8,25 +8,13 @@ export function getCharacterPreset(id) {
}
export function validateCharacterDocument(input) {
- if (!input || typeof input !== 'object' || Array.isArray(input)) {
- throw new TypeError('Character document must be an object.');
- }
- if (input.format !== 'arcode-persona-character') {
- return Object.freeze({ config: validateAvatarConfig(input), profile: null });
- }
- if (input.formatVersion !== 1) throw new TypeError('Unsupported character document version.');
- if (typeof input.id !== 'string' || !/^[a-z0-9][a-z0-9-]{0,63}$/.test(input.id)) {
- throw new TypeError('Invalid character id.');
- }
- if (typeof input.name !== 'string' || !input.name.trim() || input.name.length > 80) {
- throw new TypeError('Invalid character name.');
- }
- if (typeof input.description !== 'string' || input.description.length > 240) {
- throw new TypeError('Invalid character description.');
- }
- if (!Array.isArray(input.tags) || input.tags.length > 12 || input.tags.some((tag) => typeof tag !== 'string' || tag.length > 32)) {
- throw new TypeError('Invalid character tags.');
- }
+ if (!input || typeof input !== 'object' || Array.isArray(input)) throw new TypeError('Character document must be an object.');
+ if (input.format !== 'arcode-persona-character') return Object.freeze({ config: validateAvatarConfig(input), profile: null });
+ if (input.formatVersion !== 1 && input.formatVersion !== 2) throw new TypeError('Unsupported character document version.');
+ if (typeof input.id !== 'string' || !/^[a-z0-9][a-z0-9-]{0,63}$/.test(input.id)) throw new TypeError('Invalid character id.');
+ if (typeof input.name !== 'string' || !input.name.trim() || input.name.length > 80) throw new TypeError('Invalid character name.');
+ if (typeof input.description !== 'string' || input.description.length > 240) throw new TypeError('Invalid character description.');
+ if (!Array.isArray(input.tags) || input.tags.length > 12 || input.tags.some((tag) => typeof tag !== 'string' || tag.length > 32)) throw new TypeError('Invalid character tags.');
return Object.freeze({
config: validateAvatarConfig(input.config),
profile: Object.freeze({ id: input.id, name: input.name.trim(), description: input.description, tags: Object.freeze([...input.tags]) })
@@ -35,12 +23,12 @@ export function validateCharacterDocument(input) {
export function createCharacterDocument(config, profile = {}) {
const safe = validateCharacterDocument({
- format: 'arcode-persona-character', formatVersion: 1,
+ format: 'arcode-persona-character', formatVersion: 2,
id: profile.id ?? 'custom', name: profile.name ?? 'Custom character',
description: profile.description ?? '', tags: profile.tags ?? ['custom'],
config: validateAvatarConfig(config)
});
- return Object.freeze({ format: 'arcode-persona-character', formatVersion: 1,
+ return Object.freeze({ format: 'arcode-persona-character', formatVersion: 2,
id: safe.profile.id, name: safe.profile.name, description: safe.profile.description,
tags: [...safe.profile.tags], config: safe.config });
}
From ee52a009586e96a850c18218630f99a47764548b Mon Sep 17 00:00:00 2001
From: H3l!0s_T3k <90980178+Ismail-Benali@users.noreply.github.com>
Date: Wed, 4 Nov 2026 21:32:37 +0000
Subject: [PATCH 09/29] Expand Moroccan character presets with anatomy and
wardrobe design data
---
data/characters.json | 296 ++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 289 insertions(+), 7 deletions(-)
diff --git a/data/characters.json b/data/characters.json
index 6698c3d..27d56da 100644
--- a/data/characters.json
+++ b/data/characters.json
@@ -1,5 +1,5 @@
{
- "schemaVersion": 1,
+ "schemaVersion": 2,
"characters": [
{
"id": "atlas-scholar",
@@ -19,7 +19,54 @@
"headwear": "none",
"expression": "neutral",
"eyes": "#38251e",
- "accessory": "none"
+ "accessory": "none",
+ "schemaVersion": 2,
+ "body": {
+ "height": 1.02,
+ "shoulderWidth": 1.04,
+ "torsoLength": 1.01,
+ "bodyDepth": 1,
+ "waistWidth": 0.98,
+ "hipWidth": 1,
+ "armLength": 1,
+ "legLength": 1.02,
+ "headScale": 0.98,
+ "neckLength": 1
+ },
+ "face": {
+ "shape": "oval",
+ "width": 0.98,
+ "height": 1,
+ "cheekboneWidth": 1.02,
+ "jawWidth": 0.96,
+ "chinWidth": 0.95,
+ "noseBridgeHeight": 1,
+ "noseLength": 1,
+ "noseWidth": 0.96,
+ "noseTip": 1,
+ "earSize": 0.95,
+ "earProtrusion": 1,
+ "earAngle": 0
+ },
+ "hairDetails": {
+ "volume": 1,
+ "density": 1,
+ "fringe": 0.2,
+ "part": "left",
+ "curl": 0.25,
+ "sideburn": 0.55,
+ "length": 1
+ },
+ "clothing": {
+ "fit": "regular",
+ "sleeveLength": 1,
+ "robeLength": 1.05,
+ "collarHeight": 1.1,
+ "embroidery": 0.75,
+ "trimColor": "#c7a45e",
+ "belt": false,
+ "layer": "single"
+ }
}
},
{
@@ -40,7 +87,54 @@
"headwear": "fez",
"expression": "smile",
"eyes": "#38251e",
- "accessory": "none"
+ "accessory": "none",
+ "schemaVersion": 2,
+ "body": {
+ "height": 1.04,
+ "shoulderWidth": 1.08,
+ "torsoLength": 1,
+ "bodyDepth": 1.04,
+ "waistWidth": 1,
+ "hipWidth": 1.02,
+ "armLength": 1.02,
+ "legLength": 1.03,
+ "headScale": 0.97,
+ "neckLength": 0.98
+ },
+ "face": {
+ "shape": "square",
+ "width": 1.04,
+ "height": 0.98,
+ "cheekboneWidth": 1.04,
+ "jawWidth": 1.12,
+ "chinWidth": 1.08,
+ "noseBridgeHeight": 1.05,
+ "noseLength": 1,
+ "noseWidth": 1.04,
+ "noseTip": 1.02,
+ "earSize": 1,
+ "earProtrusion": 1,
+ "earAngle": 2
+ },
+ "hairDetails": {
+ "volume": 0.9,
+ "density": 1,
+ "fringe": 0.1,
+ "part": "none",
+ "curl": 0.2,
+ "sideburn": 0.8,
+ "length": 0.8
+ },
+ "clothing": {
+ "fit": "loose",
+ "sleeveLength": 1.04,
+ "robeLength": 1.08,
+ "collarHeight": 1.2,
+ "embroidery": 0.55,
+ "trimColor": "#c7a45e",
+ "belt": false,
+ "layer": "single"
+ }
}
},
{
@@ -61,7 +155,54 @@
"headwear": "none",
"expression": "smile",
"eyes": "#38251e",
- "accessory": "earring"
+ "accessory": "earring",
+ "schemaVersion": 2,
+ "body": {
+ "height": 1,
+ "shoulderWidth": 0.96,
+ "torsoLength": 1,
+ "bodyDepth": 0.96,
+ "waistWidth": 0.92,
+ "hipWidth": 1,
+ "armLength": 1,
+ "legLength": 1,
+ "headScale": 1,
+ "neckLength": 1.02
+ },
+ "face": {
+ "shape": "heart",
+ "width": 0.98,
+ "height": 1,
+ "cheekboneWidth": 1.08,
+ "jawWidth": 0.86,
+ "chinWidth": 0.82,
+ "noseBridgeHeight": 0.98,
+ "noseLength": 0.94,
+ "noseWidth": 0.9,
+ "noseTip": 0.98,
+ "earSize": 0.94,
+ "earProtrusion": 1,
+ "earAngle": 0
+ },
+ "hairDetails": {
+ "volume": 1.2,
+ "density": 1.1,
+ "fringe": 0.45,
+ "part": "center",
+ "curl": 0.15,
+ "sideburn": 0.2,
+ "length": 1.25
+ },
+ "clothing": {
+ "fit": "slim",
+ "sleeveLength": 0.98,
+ "robeLength": 1,
+ "collarHeight": 1.25,
+ "embroidery": 0.95,
+ "trimColor": "#d8b66b",
+ "belt": true,
+ "layer": "ceremonial"
+ }
}
},
{
@@ -81,7 +222,54 @@
"headwear": "none",
"expression": "smile",
"eyes": "#92704b",
- "accessory": "earring"
+ "accessory": "earring",
+ "schemaVersion": 2,
+ "body": {
+ "height": 1,
+ "shoulderWidth": 0.98,
+ "torsoLength": 1.02,
+ "bodyDepth": 1,
+ "waistWidth": 0.94,
+ "hipWidth": 1.03,
+ "armLength": 1,
+ "legLength": 1,
+ "headScale": 1.02,
+ "neckLength": 1
+ },
+ "face": {
+ "shape": "oval",
+ "width": 1,
+ "height": 1.02,
+ "cheekboneWidth": 1.03,
+ "jawWidth": 0.9,
+ "chinWidth": 0.9,
+ "noseBridgeHeight": 1,
+ "noseLength": 0.96,
+ "noseWidth": 0.92,
+ "noseTip": 1,
+ "earSize": 0.95,
+ "earProtrusion": 0.95,
+ "earAngle": 0
+ },
+ "hairDetails": {
+ "volume": 1.25,
+ "density": 1.15,
+ "fringe": 0.55,
+ "part": "right",
+ "curl": 0.35,
+ "sideburn": 0.2,
+ "length": 1.3
+ },
+ "clothing": {
+ "fit": "regular",
+ "sleeveLength": 1,
+ "robeLength": 1.04,
+ "collarHeight": 1.2,
+ "embroidery": 1,
+ "trimColor": "#bfa16a",
+ "belt": true,
+ "layer": "ceremonial"
+ }
}
},
{
@@ -101,7 +289,54 @@
"headwear": "none",
"expression": "neutral",
"eyes": "#55718c",
- "accessory": "glasses"
+ "accessory": "glasses",
+ "schemaVersion": 2,
+ "body": {
+ "height": 1.03,
+ "shoulderWidth": 1.02,
+ "torsoLength": 1,
+ "bodyDepth": 1,
+ "waistWidth": 1,
+ "hipWidth": 1,
+ "armLength": 1.02,
+ "legLength": 1.03,
+ "headScale": 0.98,
+ "neckLength": 1
+ },
+ "face": {
+ "shape": "long",
+ "width": 0.94,
+ "height": 1.08,
+ "cheekboneWidth": 0.96,
+ "jawWidth": 0.94,
+ "chinWidth": 0.9,
+ "noseBridgeHeight": 1.02,
+ "noseLength": 1.08,
+ "noseWidth": 0.9,
+ "noseTip": 1,
+ "earSize": 0.95,
+ "earProtrusion": 1,
+ "earAngle": 0
+ },
+ "hairDetails": {
+ "volume": 1.15,
+ "density": 1,
+ "fringe": 0.25,
+ "part": "left",
+ "curl": 0.8,
+ "sideburn": 0.45,
+ "length": 0.85
+ },
+ "clothing": {
+ "fit": "regular",
+ "sleeveLength": 1,
+ "robeLength": 0.98,
+ "collarHeight": 0.9,
+ "embroidery": 0.25,
+ "trimColor": "#b7c1b5",
+ "belt": false,
+ "layer": "single"
+ }
}
},
{
@@ -121,7 +356,54 @@
"headwear": "hood",
"expression": "smile",
"eyes": "#92704b",
- "accessory": "scarf"
+ "accessory": "scarf",
+ "schemaVersion": 2,
+ "body": {
+ "height": 1.04,
+ "shoulderWidth": 1.06,
+ "torsoLength": 1.02,
+ "bodyDepth": 1.05,
+ "waistWidth": 1.04,
+ "hipWidth": 1.08,
+ "armLength": 1.02,
+ "legLength": 1.02,
+ "headScale": 1,
+ "neckLength": 0.96
+ },
+ "face": {
+ "shape": "round",
+ "width": 1.08,
+ "height": 0.96,
+ "cheekboneWidth": 1.08,
+ "jawWidth": 1.02,
+ "chinWidth": 1.05,
+ "noseBridgeHeight": 0.98,
+ "noseLength": 0.94,
+ "noseWidth": 1.08,
+ "noseTip": 1.05,
+ "earSize": 1.04,
+ "earProtrusion": 1.05,
+ "earAngle": 4
+ },
+ "hairDetails": {
+ "volume": 1.2,
+ "density": 1.15,
+ "fringe": 0.15,
+ "part": "none",
+ "curl": 0.9,
+ "sideburn": 0.7,
+ "length": 0.9
+ },
+ "clothing": {
+ "fit": "loose",
+ "sleeveLength": 1.08,
+ "robeLength": 1.1,
+ "collarHeight": 1.1,
+ "embroidery": 0.7,
+ "trimColor": "#d0ad68",
+ "belt": false,
+ "layer": "single"
+ }
}
}
]
From acf906af74a76fa43475f2f383c749de74ec95a3 Mon Sep 17 00:00:00 2001
From: H3l!0s_T3k <90980178+Ismail-Benali@users.noreply.github.com>
Date: Wed, 4 Nov 2026 21:33:48 +0000
Subject: [PATCH 10/29] Connect character anatomy and style JSON to Three.js
---
app.js | 130 +++++++++++++++++++++++++++++++++++++++++----------------
1 file changed, 94 insertions(+), 36 deletions(-)
diff --git a/app.js b/app.js
index bf44768..63272cd 100644
--- a/app.js
+++ b/app.js
@@ -37,7 +37,7 @@ const rim=new THREE.DirectionalLight(0x9bc9b5,2.3);rim.position.set(3,3,-4);scen
const floor=new THREE.Mesh(new THREE.CircleGeometry(2.25,64),new THREE.MeshBasicMaterial({color:0x9cb79a,transparent:true,opacity:.08}));floor.rotation.x=-Math.PI/2;floor.position.y=-1.43;scene.add(floor);
const model=new THREE.Group();scene.add(model);
const state={...DEFAULT_AVATAR_CONFIG};
-const STORAGE_KEY='arcode-persona:look:v1';
+const STORAGE_KEY='arcode-persona:look:v2';
const importedRoot=new THREE.Group();
scene.add(importedRoot);
let importedAvatar=null;
@@ -55,42 +55,52 @@ function curve(parent,points,material,r=.018){const path=new THREE.CatmullRomCur
function build(){
while(model.children.length) {const o=model.children[0];model.remove(o);o.traverse(n=>{n.geometry?.dispose();if(n.material){for(const material of (Array.isArray(n.material)?n.material:[n.material])) material.dispose()}})}
const skin=skinMat(),hair=mat(state.hair),cloth=mat(state.cloth,.58),gold=mat('#c7a45e',.34,.68),dark=mat('#251e1a'),white=mat('#f5eee1'),eye=mat(state.eyes,.3);
+ const body=state.body,face=state.face,hairDesign=state.hairDetails,wardrobe=state.clothing;
+ const fitScale={slim:.92,regular:1,loose:1.08,oversized:1.16}[wardrobe.fit];
+ const clothMaterial=mat(state.cloth,.58),trim=mat(wardrobe.trimColor,.34,.62);
const torso=new THREE.Group();model.add(torso);
- // Robe / outfit silhouette
+ torso.scale.set(body.shoulderWidth*fitScale,body.torsoLength,body.bodyDepth);
+ const robeHeight=(state.outfit==='modern'?1.13:1.48)*wardrobe.robeLength;
if(state.outfit==='modern'){
- cylinder(torso,.49,.63,1.13,0,-.42,0,cloth);
- sphere(torso,0,.13,0,.48,.34,.29,cloth);
- cylinder(torso,.18,.2,.24,0,.28,0,skin);
+ cylinder(torso,.49*fitScale,.63*fitScale,robeHeight,0,-.42,0,clothMaterial);
+ sphere(torso,0,.13,0,.48*fitScale,.34,.29,clothMaterial);
+ cylinder(torso,.18,.2,.24*wardrobe.collarHeight,0,.28,0,skin);
}else{
- cylinder(torso,.42,.62,1.48,0,-.48,0,cloth);
- sphere(torso,0,.16,0,.47,.34,.31,cloth);
- cylinder(torso,.17,.19,.22,0,.31,0,skin);
- // embroidered front line and neckline
- curve(torso,[[0,.2,.315],[0,-.15,.38],[0,-.65,.53],[0,-1.15,.55]],gold,.014);
- curve(torso,[[-.13,.28,.27],[0,.17,.34],[.13,.28,.27]],gold,.012);
- for(let y=-.05;y>-.95;y-=.18){sphere(torso,0,y,.39,.025,.025,.012,gold,12)}
- if(state.outfit==='takchita'){cylinder(torso,.5,.68,1.55,0,-.48,-.015,mat('#d8c7a0',.45),48).material.transparent=true;torso.children[torso.children.length-1].material.opacity=.22}
- if(state.outfit==='caftan'){curve(torso,[[-.34,.15,.23],[-.25,-.2,.33],[0,-.8,.57],[.25,-.2,.33],[.34,.15,.23]],gold,.018)}
- if(state.outfit==='djellaba'){const hood=sphere(torso,0,.49,-.18,.36,.25,.22,cloth);hood.visible=state.headwear==='hood'}
+ const waist=.42*(wardrobe.fit==='slim'?.92:wardrobe.fit==='oversized'?1.12:1);
+ cylinder(torso,waist,.62*fitScale,robeHeight,0,-.48,0,clothMaterial);
+ sphere(torso,0,.16,0,.47*fitScale,.34,.31,clothMaterial);
+ cylinder(torso,.17,.19,.22*wardrobe.collarHeight,0,.31,0,skin);
+ curve(torso,[[0,.2,.315],[0,-.15,.38],[0,-.65,.53],[0,-1.15*wardrobe.robeLength,.55]],trim,.009+.012*wardrobe.embroidery);
+ curve(torso,[[-.13,.28,.27],[0,.17,.34],[.13,.28,.27]],trim,.008+.012*wardrobe.embroidery);
+ const stitchCount=Math.round(wardrobe.embroidery*7);
+ for(let i=0;i.05)sphere(head,0,.34,.39,.3*volume,.08+hairDesign.fringe*.13,.16*volume,hair);
+ if(hairDesign.sideburn>.05)for(const s of [-1,1])sphere(head,s*.49,-.04,.12,.055,.12+hairDesign.sideburn*.12,.08,hair);
+ if(hairDesign.part!=='none'){const x=hairDesign.part==='left'?.12:hairDesign.part==='right'?-.12:0;curve(head,[[x,.72,.08],[x,.68,.22],[x,.57,.36]],mat('#5b5148'),.008)}
}
// brows and eyes
faceParts={eyes:[],mouth:null};
@@ -100,7 +110,7 @@ function build(){
faceParts.eyes.push(sphere(head,s*.235,.035,.472,.038,.045,.018,eye,20));
sphere(head,s*.235,.035,.488,.016,.02,.009,dark,16);
}
- sphere(head,0,-.08,.47,.07,.14,.075,skin);
+ sphere(head,0,-.08,.47,.055*face.noseWidth,.14*face.noseLength,.075*face.noseBridgeHeight,skin);sphere(head,0,-.15,.51,.07*face.noseWidth,.045*face.noseTip,.07,skin,20);
faceParts.mouth=curve(head,[[-.14,-.29,.43],[0,-.34,.47],[.14,-.29,.43]],mat('#6b302d'),.018);
if(state.expression==='neutral'){faceParts.mouth.scale.y=.45}
if(state.expression==='surprised'){faceParts.mouth.scale.set(.55,1.8,1)}
@@ -138,9 +148,56 @@ renderer.domElement.addEventListener('wheel',e=>{e.preventDefault();zoom=THREE.M
function animate(){requestAnimationFrame(animate);const delta=clock.getDelta();const t=clock.elapsedTime;if(importedMixer)importedMixer.update(delta);if(auto&&!dragging)rotation+=.0025;model.rotation.y=rotation;model.position.y=Math.sin(t*1.5)*.025;model.rotation.z=Math.sin(t*.8)*.012;importedRoot.rotation.y=rotation;importedRoot.position.y=model.position.y;renderer.render(scene,camera)}
animate();
document.getElementById('loading').classList.add('hidden');
-function update(){build();persistLook()}
+function update(){build();applyImportedCharacterDesign();persistLook()}
+function applyImportedCharacterDesign(){
+ if(!importedAvatar)return;
+ const design=state;
+ const morphAliases={
+ 'FaceWidth':['facewidth','headwidth'], 'FaceHeight':['faceheight','headheight'],
+ 'CheekWidth':['cheekwidth','cheekbonewidth'], 'JawWidth':['jawwidth','jawwide'],
+ 'JawNarrow':['jawnarrow'], 'ChinWidth':['chinwidth'], 'NoseWidth':['nosewidth'],
+ 'NoseNarrow':['nosenarrow'], 'NoseLength':['noselength'], 'NoseShort':['noseshort'],
+ 'NoseBridge':['nosebridgeheight'], 'EarSize':['earsize'], 'EarProtrusion':['earprotrusion'],
+ 'HeadScale':['headscale']
+ };
+ const targets={
+ facewidth:design.face.width, headwidth:design.face.width,
+ faceheight:design.face.height, headheight:design.face.height,
+ cheekwidth:design.face.cheekboneWidth, cheekbonewidth:design.face.cheekboneWidth,
+ jawwidth:design.face.jawWidth, jawwide:design.face.jawWidth,
+ jawnarrow:2-design.face.jawWidth, chinwidth:design.face.chinWidth,
+ nosewidth:design.face.noseWidth, nosenarrow:2-design.face.noseWidth,
+ noselength:design.face.noseLength, noseshort:2-design.face.noseLength,
+ nosebridgeheight:design.face.noseBridgeHeight, earsize:design.face.earSize,
+ earprotrusion:design.face.earProtrusion, headscale:design.body.headScale
+ };
+ importedAvatar.traverse(node=>{
+ if(node.isSkinnedMesh&&node.morphTargetDictionary&&node.morphTargetInfluences){
+ for(const [name,index] of Object.entries(node.morphTargetDictionary)){
+ const key=name.toLowerCase().replace(/[^a-z]/g,'');
+ if(Object.prototype.hasOwnProperty.call(targets,key)){
+ const value=THREE.MathUtils.clamp((targets[key]-1)*2.5,0,1);
+ node.morphTargetInfluences[index]=value;
+ }
+ }
+ }
+ if(node.isBone){
+ const name=node.name.toLowerCase().replace(/[^a-z]/g,'');
+ const base=node.userData.arcodeBaseScale||(node.userData.arcodeBaseScale=node.scale.clone());
+ let x=1,y=1;
+ if(/shoulder|clavicle|upperarm/.test(name))x=design.body.shoulderWidth;
+ if(/spine|chest|torso/.test(name))y=design.body.torsoLength;
+ if(/hips|pelvis/.test(name))x=design.body.hipWidth;
+ if(/upperleg|thigh|upleg/.test(name))y=design.body.legLength;
+ if(/lowerleg|calf|shin/.test(name))y=design.body.legLength;
+ if(/neck/.test(name))y=design.body.neckLength;
+ if(/head/.test(name))x=y=design.body.headScale;
+ node.scale.set(base.x*x,base.y*y,base.z);
+ }
+ });
+}
function persistLook(){try{localStorage.setItem(STORAGE_KEY,JSON.stringify(validateAvatarConfig(state)))}catch(error){console.warn('Unable to save persona locally:',error)}}
-function restoreLook(input){try{const characterDocument=validateCharacterDocument(input);Object.assign(state,characterDocument.config);const selector=globalThis.document.getElementById('characterPreset');if(selector)selector.value=characterDocument.profile?.id||'';syncControls();update();toast(characterDocument.profile?'تم استيراد ملف الشخصية':'تمت استعادة الإطلالة')}catch(error){toast('ملف الشخصية غير صالح أو غير مدعوم');console.error(error)}}
+function restoreLook(input){try{const characterDocument=validateCharacterDocument(input);Object.assign(state,characterDocument.config);syncDesignControls();const selector=globalThis.document.getElementById('characterPreset');if(selector)selector.value=characterDocument.profile?.id||'';syncControls();update();toast(characterDocument.profile?'تم استيراد ملف الشخصية':'تمت استعادة الإطلالة')}catch(error){toast('ملف الشخصية غير صالح أو غير مدعوم');console.error(error)}}
function syncControls(){
const keys={skin:'skinOptions',hair:'hairOptions',cloth:'clothOptions'};
for(const [key,id] of Object.entries(keys))document.querySelectorAll(`#${id} .swatch`).forEach(b=>b.classList.toggle('selected',b.dataset.value===state[key]));
@@ -299,6 +356,7 @@ async function importAvatarAsset(file){
importedAvatar=normalizedRoot;
importedRoot.add(normalizedRoot);
buildMorphControls(root);
+ applyImportedCharacterDesign();
importedMixer=new THREE.AnimationMixer(root);
importedActions=gltf.animations.map(clip=>importedMixer.clipAction(clip));
animationSelect.replaceChildren(new Option('اختر الحركة',''));
@@ -380,12 +438,12 @@ function removeAvatarAsset(){
}
function toast(msg){const el=document.getElementById('toast');el.textContent=msg;el.classList.add('show');setTimeout(()=>el.classList.remove('show'),2300)}
-function reset(){Object.assign(state,DEFAULT_AVATAR_CONFIG);syncControls();rotation=0;zoom=7.6;camera.position.set(0,1.45,zoom);auto=true;document.getElementById('rotate').classList.add('active');document.getElementById('rotate').innerHTML='⟳ دوران تلقائي';update();toast('تمت إعادة الإطلالة الافتراضية')}
+function reset(){Object.assign(state,validateAvatarConfig(DEFAULT_AVATAR_CONFIG));syncControls();rotation=0;zoom=7.6;camera.position.set(0,1.45,zoom);auto=true;document.getElementById('rotate').classList.add('active');document.getElementById('rotate').innerHTML='⟳ دوران تلقائي';update();toast('تمت إعادة الإطلالة الافتراضية')}
document.getElementById('resetTop').addEventListener('click',reset);
-document.getElementById('randomize').addEventListener('click',()=>{const pick=a=>a[Math.floor(Math.random()*a.length)];state.skin=pick(['#b97850','#e0a77d','#8e573d','#603b30','#c98d70']);state.hair=pick(['#241b19','#57352a','#b78b53']);state.cloth=pick(['#176b60','#172b50','#873f49','#d1b16d']);state.outfit=pick(['djellaba','caftan','modern','takchita']);state.expression=pick(['smile','neutral','surprised']);update();toast('تم ابتكار إطلالة جديدة')});
+document.getElementById('randomize').addEventListener('click',()=>{const pick=a=>a[Math.floor(Math.random()*a.length)];state.body.shoulderWidth=pick([.92,1,1.08]);state.face.shape=pick(['oval','round','square','heart','long']);state.face.noseWidth=pick([.9,1,1.1]);state.skin=pick(['#b97850','#e0a77d','#8e573d','#603b30','#c98d70']);state.hair=pick(['#241b19','#57352a','#b78b53']);state.cloth=pick(['#176b60','#172b50','#873f49','#d1b16d']);state.outfit=pick(['djellaba','caftan','modern','takchita']);state.expression=pick(['smile','neutral','surprised']);update();toast('تم ابتكار إطلالة جديدة')});
document.getElementById('saveLook').addEventListener('click',()=>{const selected=getCharacterPreset(document.getElementById('characterPreset')?.value);const data=createCharacterDocument(state,selected||{id:'custom',name:'شخصيتي المخصصة',description:'شخصية مخصصة أنشأها المستخدم.',tags:['custom']});const blob=new Blob([JSON.stringify(data,null,2)],{type:'application/json'});const url=URL.createObjectURL(blob);const a=document.createElement('a');a.href=url;a.download='arcode-persona-look.json';a.click();setTimeout(()=>URL.revokeObjectURL(url),1000);toast('تم تصدير إعدادات الشخصية')});
const characterPreset=document.getElementById('characterPreset');
-if(characterPreset){for(const item of CHARACTER_CATALOG.characters){const option=document.createElement('option');option.value=item.id;option.textContent=item.name+' — '+item.description;characterPreset.appendChild(option)}characterPreset.addEventListener('change',()=>{if(!characterPreset.value)return;try{const preset=getCharacterPreset(characterPreset.value);Object.assign(state,validateAvatarConfig(preset.config));syncControls();update();toast('تم تطبيق تصميم '+preset.name)}catch(error){console.error(error);toast('تعذر تطبيق تصميم الشخصية')}})}
+if(characterPreset){for(const item of CHARACTER_CATALOG.characters){const option=document.createElement('option');option.value=item.id;option.textContent=item.name+' — '+item.description;characterPreset.appendChild(option)}characterPreset.addEventListener('change',()=>{if(!characterPreset.value)return;try{const preset=getCharacterPreset(characterPreset.value);Object.assign(state,validateAvatarConfig(preset.config));syncControls();syncDesignControls();update();toast('تم تطبيق تصميم '+preset.name)}catch(error){console.error(error);toast('تعذر تطبيق تصميم الشخصية')}})}
const importInput=document.getElementById('importLookFile');
document.getElementById('importLook').addEventListener('click',()=>importInput.click());
importInput.addEventListener('change',async()=>{const file=importInput.files?.[0];if(!file)return;if(file.size>64*1024){toast('حجم ملف الإطلالة أكبر من المسموح');importInput.value='';return}try{restoreLook(JSON.parse(await file.text()))}catch(error){toast('تعذر قراءة ملف الإطلالة');console.error(error)}finally{importInput.value=''}});
From 6172da1f3517e6a619b8ae0b934d690871f8eb8d Mon Sep 17 00:00:00 2001
From: H3l!0s_T3k <90980178+Ismail-Benali@users.noreply.github.com>
Date: Wed, 4 Nov 2026 21:33:50 +0000
Subject: [PATCH 11/29] Add live body face hair and clothing design controls
---
index.html | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/index.html b/index.html
index 31ad5fe..e8f68fc 100644
--- a/index.html
+++ b/index.html
@@ -57,6 +57,10 @@ اصنع شخصية تشبهك.