@umituz/web-virtual 2.2.0 → 2.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umituz/web-virtual",
3
- "version": "2.2.0",
3
+ "version": "2.3.1",
4
4
  "description": "Universal 3D Virtual Environment Engine for Web & React — Offices, Farms, Factories, Schools, Hospitals with 60fps performance, raycasting and interactive entities.",
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
@@ -76,4 +76,18 @@ describe('rebindSkinnedSkeletons', () => {
76
76
  const cloneMesh = clone.getObjectByName('body-mesh') as THREE.SkinnedMesh
77
77
  expect(cloneMesh.skeleton).toBe(skeleton)
78
78
  })
79
+
80
+ it('preserves animation clips when cloning rigged groups', () => {
81
+ const { root } = makeRiggedGroup()
82
+ const clip = new THREE.AnimationClip('sit', 1.0, [
83
+ new THREE.VectorKeyframeTrack('root.position', [0, 1], [0, 0, 0, 0, -0.15, 0]),
84
+ ])
85
+ root.animations = [clip]
86
+
87
+ // Clone and verify animations are retained
88
+ const clone = root.clone(true)
89
+ clone.animations = root.animations ? [...root.animations] : []
90
+ expect(clone.animations).toHaveLength(1)
91
+ expect(clone.animations?.[0]?.name).toBe('sit')
92
+ })
79
93
  })
@@ -72,6 +72,8 @@ export class ModelLoader {
72
72
  resolvedPath,
73
73
  (gltf) => {
74
74
  const root = gltf.scene
75
+ // Preserve animation clips on the scene root for AnimationMixer consumers
76
+ root.animations = gltf.animations || []
75
77
 
76
78
  // Configure shadows and PBR properties across all child meshes
77
79
  root.traverse((node) => {
@@ -121,11 +123,20 @@ export class ModelLoader {
121
123
  await Promise.all(assetIds.map((id) => this.load(id)))
122
124
  }
123
125
 
126
+ getAnimations(assetIdOrPath: string): THREE.AnimationClip[] {
127
+ const meta: AssetMetadata | undefined = ASSET_CATALOG[assetIdOrPath]
128
+ const rawPath = meta ? meta.path : assetIdOrPath
129
+ const resolvedPath = this.basePath ? `${this.basePath}${rawPath}` : rawPath
130
+ return this.cache.get(resolvedPath)?.animations || []
131
+ }
132
+
124
133
  private cloneGroup(source: THREE.Group, meta?: AssetMetadata): THREE.Group {
125
134
  const cloned = source.clone(true)
126
135
  // Skinned meshes cannot share a skeleton across clones — rebind each
127
136
  // clone to the bones inside its own hierarchy (see rebindSkinnedSkeletons).
128
137
  rebindSkinnedSkeletons(cloned)
138
+ // Preserve animation clips on cloned hierarchies for THREE.AnimationMixer
139
+ cloned.animations = source.animations ? [...source.animations] : []
129
140
  if (meta && meta.defaultScale) {
130
141
  if (typeof meta.defaultScale === 'number') {
131
142
  cloned.scale.setScalar(meta.defaultScale)
@@ -3,13 +3,24 @@ import * as THREE from 'three'
3
3
  import { createAnimal, createHerd } from './AnimalBuilder'
4
4
 
5
5
  describe('createAnimal', () => {
6
- it.each(['cow', 'sheep', 'goat', 'chicken'] as const)('builds a %s with a head pivot', (species) => {
6
+ it.each(
7
+ [
8
+ 'cow', 'buffalo', 'sheep', 'goat', 'horse', 'pig', 'rabbit',
9
+ 'chicken', 'turkey', 'quail', 'duck', 'goose',
10
+ ] as const,
11
+ )('builds a %s with a head pivot', (species) => {
7
12
  const animal = createAnimal({ species })
8
13
  expect(animal.getObjectByName('animal-neck')).toBeTruthy()
9
14
  expect(animal.getObjectByName('animal-head')).toBeTruthy()
10
15
  expect(animal.children.length).toBeGreaterThan(3)
11
16
  })
12
17
 
18
+ it('falls back to the cow silhouette for an unknown species instead of crashing', () => {
19
+ const junk = createAnimal({ species: 'space-whale' as never })
20
+ expect(junk.getObjectByName('animal-head')).toBeTruthy()
21
+ expect(junk.name).toBe('animal-space-whale')
22
+ })
23
+
13
24
  it('scales uniformly', () => {
14
25
  const animal = createAnimal({ species: 'cow', scale: 2 })
15
26
  expect(animal.scale.x).toBe(2)
@@ -19,6 +30,14 @@ describe('createAnimal', () => {
19
30
  })
20
31
 
21
32
  describe('createHerd', () => {
33
+ it('never crashes a scene build on an unknown species (regression: live farm crash)', () => {
34
+ const herd = createHerd({ species: 'emu' as never, count: 3 })
35
+ expect(herd.children).toHaveLength(3)
36
+ for (const child of herd.children) {
37
+ expect(child.getObjectByName('animal-head')).toBeTruthy()
38
+ }
39
+ })
40
+
22
41
  it('creates exactly count animals inside the grazing area', () => {
23
42
  const herd = createHerd({ species: 'cow', count: 9, area: { width: 8, depth: 6 }, center: [3, 0, 4] })
24
43
  const animals = herd.children.filter((c) => c.name === 'animal-cow')
@@ -9,7 +9,9 @@ import type { WorldTickFn, UnregisterTick } from '../../core/types'
9
9
  * deterministically from a seed — same seed, same scene, every time.
10
10
  */
11
11
 
12
- export type AnimalSpecies = 'cow' | 'sheep' | 'goat' | 'chicken'
12
+ export type AnimalSpecies =
13
+ | 'cow' | 'buffalo' | 'sheep' | 'goat' | 'horse' | 'pig' | 'rabbit'
14
+ | 'chicken' | 'turkey' | 'quail' | 'duck' | 'goose'
13
15
 
14
16
  export interface AnimalOptions {
15
17
  species?: AnimalSpecies
@@ -25,14 +27,30 @@ const SPECIES_DEFAULTS: Record<
25
27
  { body: string; accent: string; bodyW: number; bodyH: number; bodyD: number; legH: number; headScale: number }
26
28
  > = {
27
29
  cow: { body: '#f5f0e6', accent: '#3d3630', bodyW: 0.62, bodyH: 0.5, bodyD: 1.05, legH: 0.42, headScale: 1 },
30
+ buffalo: { body: '#4a443c', accent: '#2b2724', bodyW: 0.68, bodyH: 0.55, bodyD: 1.1, legH: 0.4, headScale: 1.05 },
28
31
  sheep: { body: '#ece7db', accent: '#4a4038', bodyW: 0.46, bodyH: 0.44, bodyD: 0.72, legH: 0.3, headScale: 0.8 },
29
32
  goat: { body: '#cbb8a0', accent: '#6b5a45', bodyW: 0.4, bodyH: 0.42, bodyD: 0.68, legH: 0.36, headScale: 0.75 },
33
+ horse: { body: '#7a5a3a', accent: '#3a2c1e', bodyW: 0.55, bodyH: 0.5, bodyD: 1.0, legH: 0.55, headScale: 0.9 },
34
+ pig: { body: '#e8b4b8', accent: '#c98a90', bodyW: 0.5, bodyH: 0.42, bodyD: 0.85, legH: 0.25, headScale: 0.85 },
35
+ rabbit: { body: '#c8c2b8', accent: '#8a8178', bodyW: 0.18, bodyH: 0.18, bodyD: 0.26, legH: 0.08, headScale: 0.6 },
30
36
  chicken: { body: '#f8f4ec', accent: '#c2452d', bodyW: 0.2, bodyH: 0.22, bodyD: 0.28, legH: 0.12, headScale: 0.5 },
37
+ turkey: { body: '#5a4a3a', accent: '#c2452d', bodyW: 0.3, bodyH: 0.3, bodyD: 0.4, legH: 0.18, headScale: 0.55 },
38
+ quail: { body: '#b8a88a', accent: '#6b5a45', bodyW: 0.14, bodyH: 0.14, bodyD: 0.2, legH: 0.07, headScale: 0.5 },
39
+ duck: { body: '#f2ede0', accent: '#d97f2e', bodyW: 0.22, bodyH: 0.2, bodyD: 0.32, legH: 0.1, headScale: 0.5 },
40
+ goose: { body: '#e8e4da', accent: '#d97f2e', bodyW: 0.26, bodyH: 0.24, bodyD: 0.4, legH: 0.14, headScale: 0.5 },
31
41
  }
32
42
 
43
+ /** Birds walk on slim legs and carry a beak; the crest is land-fowl only. */
44
+ const BIRD_SPECIES = new Set<AnimalSpecies>(['chicken', 'turkey', 'quail', 'duck', 'goose'])
45
+ const CRESTED_SPECIES = new Set<AnimalSpecies>(['chicken', 'turkey', 'quail'])
46
+ const HORNED_SPECIES = new Set<AnimalSpecies>(['goat', 'buffalo'])
47
+
33
48
  export function createAnimal(options: AnimalOptions = {}): THREE.Group {
34
49
  const { species = 'cow', bodyColor, scale = 1, seed = 1 } = options
35
- const d = SPECIES_DEFAULTS[species]
50
+ // Unknown codes (junk data, a consumer's newer vocabulary) fall back to
51
+ // the cow silhouette instead of crashing the scene build.
52
+ const d = SPECIES_DEFAULTS[species] ?? SPECIES_DEFAULTS.cow
53
+ const isBird = BIRD_SPECIES.has(species)
36
54
  const rng = createRng(seed)
37
55
 
38
56
  const group = new THREE.Group()
@@ -53,8 +71,8 @@ export function createAnimal(options: AnimalOptions = {}): THREE.Group {
53
71
  body.castShadow = true
54
72
  group.add(body)
55
73
 
56
- // Patch on cows / sheep (a darker back patch reads as a breed marker)
57
- if (species === 'cow' || species === 'sheep') {
74
+ // Patch on bovids (a darker back patch reads as a breed marker)
75
+ if (species === 'cow' || species === 'buffalo' || species === 'sheep') {
58
76
  const patch = new THREE.Mesh(
59
77
  new THREE.BoxGeometry(bw * 1.02, bh * 0.5, bd * (0.3 + rng() * 0.3)),
60
78
  accentMat,
@@ -71,20 +89,22 @@ export function createAnimal(options: AnimalOptions = {}): THREE.Group {
71
89
 
72
90
  const head = new THREE.Mesh(
73
91
  new THREE.BoxGeometry(bw * 0.45 * d.headScale, bh * 0.5 * d.headScale, bw * 0.5 * d.headScale),
74
- species === 'chicken' ? accentMat : bodyMat,
92
+ isBird ? accentMat : bodyMat,
75
93
  )
76
94
  head.name = 'animal-head'
77
95
  head.position.set(0, bh * 0.15, bw * 0.28 * d.headScale)
78
96
  head.castShadow = true
79
97
  neck.add(head)
80
98
 
81
- if (species === 'chicken') {
82
- const comb = new THREE.Mesh(
83
- new THREE.BoxGeometry(bw * 0.12, bh * 0.22, bw * 0.2),
84
- accentMat,
85
- )
86
- comb.position.set(0, bh * 0.42, 0)
87
- neck.add(comb)
99
+ if (isBird) {
100
+ if (CRESTED_SPECIES.has(species)) {
101
+ const comb = new THREE.Mesh(
102
+ new THREE.BoxGeometry(bw * 0.12, bh * 0.22, bw * 0.2),
103
+ accentMat,
104
+ )
105
+ comb.position.set(0, bh * 0.42, 0)
106
+ neck.add(comb)
107
+ }
88
108
  const beak = new THREE.Mesh(
89
109
  new THREE.ConeGeometry(bw * 0.07, bh * 0.22, 4),
90
110
  new THREE.MeshStandardMaterial({ color: '#d9a441', roughness: 0.8 }),
@@ -93,16 +113,17 @@ export function createAnimal(options: AnimalOptions = {}): THREE.Group {
93
113
  beak.position.set(0, bh * 0.05, bw * 0.55 * d.headScale)
94
114
  neck.add(beak)
95
115
  } else {
96
- // Ears / horns
116
+ // Ears — tall and slender on a rabbit, stubby on the rest
117
+ const earH = species === 'rabbit' ? bh * 0.55 : bh * 0.14
97
118
  for (const side of [-1, 1]) {
98
119
  const ear = new THREE.Mesh(
99
- new THREE.BoxGeometry(bw * 0.12, bh * 0.14, bw * 0.08),
120
+ new THREE.BoxGeometry(bw * 0.12, earH, bw * 0.08),
100
121
  accentMat,
101
122
  )
102
- ear.position.set(side * bw * 0.25 * d.headScale, bh * 0.28, -bw * 0.05)
123
+ ear.position.set(side * bw * 0.25 * d.headScale, bh * 0.28 + earH * 0.4, -bw * 0.05)
103
124
  neck.add(ear)
104
125
  }
105
- if (species === 'goat') {
126
+ if (HORNED_SPECIES.has(species)) {
106
127
  for (const side of [-1, 1]) {
107
128
  const horn = new THREE.Mesh(
108
129
  new THREE.ConeGeometry(bw * 0.05, bh * 0.35, 4),
@@ -115,11 +136,10 @@ export function createAnimal(options: AnimalOptions = {}): THREE.Group {
115
136
  }
116
137
  }
117
138
 
118
- // Legs (chickens get slim cylinder legs; others chunky boxes)
119
- const legGeo =
120
- species === 'chicken'
121
- ? new THREE.CylinderGeometry(0.015, 0.015, d.legH, 4)
122
- : new THREE.BoxGeometry(bw * 0.16, d.legH, bw * 0.16)
139
+ // Legs (birds get slim cylinder legs; quadrupeds chunky boxes)
140
+ const legGeo = isBird
141
+ ? new THREE.CylinderGeometry(0.015, 0.015, d.legH, 4)
142
+ : new THREE.BoxGeometry(bw * 0.16, d.legH, bw * 0.16)
123
143
  for (const [lx, lz] of [
124
144
  [-1, -1],
125
145
  [1, -1],
@@ -134,7 +154,7 @@ export function createAnimal(options: AnimalOptions = {}): THREE.Group {
134
154
  // Tail
135
155
  const tail = new THREE.Mesh(
136
156
  new THREE.BoxGeometry(bw * 0.12, bh * 0.3, bw * 0.08),
137
- species === 'chicken' ? bodyMat : accentMat,
157
+ isBird ? bodyMat : accentMat,
138
158
  )
139
159
  tail.position.set(0, d.legH + bh * 0.9, -bd / 2 - bw * 0.02)
140
160
  tail.name = 'animal-tail'
@@ -24,8 +24,9 @@ export function createStylizedAvatar(
24
24
  : parseInt(String(entity.pinNumber || '1'), 10) || 1
25
25
  const seed = (pinNum * 2.39996) + ((entity.id.charCodeAt(0) || 1) * 0.15)
26
26
 
27
- // Status Material
28
- const statusMat = materials.getStatusGlow(entity.status || 'idle')
27
+ // Status state
28
+ let currentStatus = entity.status || 'idle'
29
+ const statusMat = materials.getStatusGlow(currentStatus)
29
30
 
30
31
  // Seated offset relative to workstation center (chair seat is at z = +0.44)
31
32
  const isExecutive = entity.id === 'slot-1' || entity.zoneId === 'executive'
@@ -49,51 +50,15 @@ export function createStylizedAvatar(
49
50
  modelsContainer.name = `character-real-${entity.id}`
50
51
  avatarRoot.add(modelsContainer)
51
52
 
52
- // Bone node references for procedural animation
53
- let realHead: THREE.Object3D | null = null
54
- let realTorso: THREE.Object3D | null = null
55
- let realLeftArm: THREE.Object3D | null = null
56
- let realRightArm: THREE.Object3D | null = null
57
-
58
- // 3. Fallback Placeholder Geometry (shown while 3D GLB model loads)
59
- const placeholderGroup = new THREE.Group()
60
- placeholderGroup.name = 'character-placeholder'
61
-
62
- const skinMat = materials.getSkinMaterial()
63
- const hairMat = materials.getHairMaterial(entity.avatarHair || '#1e1b4b')
64
- const clothesMat = materials.getClothingMaterial(entity.avatarColor || '#2563eb')
65
- const pantsMat = materials.getDarkSlate('#1e293b')
66
-
67
- const thighs = new THREE.Mesh(new THREE.BoxGeometry(0.36, 0.12, 0.38), pantsMat)
68
- thighs.position.set(0, 0.48, -0.16)
69
- thighs.userData = { entityId: entity.id }
70
- placeholderGroup.add(thighs)
71
-
72
- const torsoPlaceholder = new THREE.Group()
73
- torsoPlaceholder.position.set(0, 0.6, 0)
74
- placeholderGroup.add(torsoPlaceholder)
75
-
76
- const torsoMesh = new THREE.Mesh(new THREE.CylinderGeometry(0.20, 0.17, 0.44, 12), clothesMat)
77
- torsoMesh.position.set(0, 0.22, 0)
78
- torsoMesh.castShadow = true
79
- torsoMesh.userData = { entityId: entity.id }
80
- torsoPlaceholder.add(torsoMesh)
81
-
82
- const headMesh = new THREE.Mesh(new THREE.SphereGeometry(0.17, 16, 16), skinMat)
83
- headMesh.position.set(0, 0.66, 0)
84
- headMesh.castShadow = true
85
- headMesh.userData = { entityId: entity.id }
86
- torsoPlaceholder.add(headMesh)
87
-
88
- const hairMesh = new THREE.Mesh(
89
- new THREE.SphereGeometry(0.178, 14, 14, 0, Math.PI * 2, 0, Math.PI * 0.55),
90
- hairMat,
53
+ // 3. Floating Status Pin Indicator (Compact, elegant glow disk)
54
+ const statusHalo = new THREE.Mesh(
55
+ new THREE.RingGeometry(0.07, 0.11, 24),
56
+ statusMat,
91
57
  )
92
- hairMesh.position.set(0, 0.69, 0)
93
- hairMesh.rotation.x = -0.1
94
- torsoPlaceholder.add(hairMesh)
95
-
96
- avatarRoot.add(placeholderGroup)
58
+ statusHalo.position.set(0, 1.7, 0)
59
+ statusHalo.rotation.x = -Math.PI / 2
60
+ statusHalo.userData = { entityId: entity.id }
61
+ avatarRoot.add(statusHalo)
97
62
 
98
63
  // 4. Select character model variety across 4 distinct models
99
64
  const charModels = [
@@ -104,123 +69,94 @@ export function createStylizedAvatar(
104
69
  ]
105
70
  const selectedCharId = charModels[pinNum % charModels.length] || 'character:male-a'
106
71
 
107
- // Load Real 3D Character Model
72
+ // Three.js AnimationMixer state
73
+ let mixer: THREE.AnimationMixer | null = null
74
+ let sitAction: THREE.AnimationAction | null = null
75
+ let interactAction: THREE.AnimationAction | null = null
76
+ let emoteAction: THREE.AnimationAction | null = null
77
+ let isWorking = currentStatus === 'running' || currentStatus === 'working'
78
+ let isAwaiting = currentStatus === 'awaiting_approval'
79
+
80
+ function syncAnimationActions() {
81
+ if (!mixer) return
82
+ if (isWorking) {
83
+ if (emoteAction) emoteAction.fadeOut(0.2)
84
+ if (interactAction) {
85
+ interactAction.reset().fadeIn(0.2).play()
86
+ }
87
+ } else if (isAwaiting) {
88
+ if (interactAction) interactAction.fadeOut(0.2)
89
+ if (emoteAction) {
90
+ emoteAction.reset().fadeIn(0.2).play()
91
+ }
92
+ } else {
93
+ if (interactAction) interactAction.fadeOut(0.2)
94
+ if (emoteAction) emoteAction.fadeOut(0.2)
95
+ if (sitAction && !sitAction.isRunning()) {
96
+ sitAction.reset().fadeIn(0.2).play()
97
+ }
98
+ }
99
+ }
100
+
101
+ // Load Real 3D Character Model and bind standard Three.js AnimationMixer
108
102
  const loader = ModelLoader.getInstance()
109
103
  void loader.load(selectedCharId).then((charModel) => {
110
- if (charModel) {
111
- placeholderGroup.visible = false
112
-
113
- // Scale and position character seated on chair
114
- charModel.scale.set(1.65, 1.65, 1.65)
115
- charModel.position.set(0, 0.44, -0.05)
116
- charModel.traverse((node) => {
117
- if (node instanceof THREE.Mesh) {
118
- node.castShadow = true
119
- node.receiveShadow = true
120
- }
121
- node.userData = { entityId: entity.id }
122
- })
123
-
124
- // Locate anatomical bone nodes
125
- realHead = charModel.getObjectByName('head') || null
126
- realTorso = charModel.getObjectByName('torso') || null
127
- realLeftArm = charModel.getObjectByName('arm-left') || null
128
- realRightArm = charModel.getObjectByName('arm-right') || null
129
-
130
- const legLeft = charModel.getObjectByName('leg-left')
131
- const legRight = charModel.getObjectByName('leg-right')
132
-
133
- // Bend legs forward at 90 degrees into natural seated posture
134
- if (legLeft) legLeft.rotation.x = -Math.PI / 2.2
135
- if (legRight) legRight.rotation.x = -Math.PI / 2.2
136
-
137
- // Position arms forward resting on desk
138
- if (realLeftArm) {
139
- realLeftArm.rotation.x = Math.PI / 2.6
140
- realLeftArm.rotation.z = -0.15
104
+ if (!charModel) return
105
+
106
+ // Scale and position character seated on chair
107
+ charModel.scale.set(1.65, 1.65, 1.65)
108
+ charModel.position.set(0, 0.44, -0.05)
109
+ charModel.traverse((node) => {
110
+ if (node instanceof THREE.Mesh) {
111
+ node.castShadow = true
112
+ node.receiveShadow = true
141
113
  }
142
- if (realRightArm) {
143
- realRightArm.rotation.x = Math.PI / 2.6
144
- realRightArm.rotation.z = 0.15
114
+ node.userData = { entityId: entity.id }
115
+ })
116
+
117
+ // Setup native Three.js AnimationMixer with GLB animations
118
+ const animations = charModel.animations || []
119
+ if (animations.length > 0) {
120
+ mixer = new THREE.AnimationMixer(charModel)
121
+
122
+ const sitClip = THREE.AnimationClip.findByName(animations, 'sit')
123
+ if (sitClip) {
124
+ sitAction = mixer.clipAction(sitClip)
125
+ sitAction.setLoop(THREE.LoopRepeat, Infinity)
126
+ sitAction.play()
145
127
  }
146
128
 
147
- modelsContainer.add(charModel)
148
- }
149
- })
129
+ const interactClip = THREE.AnimationClip.findByName(animations, 'interact-right')
130
+ if (interactClip) {
131
+ interactAction = mixer.clipAction(interactClip)
132
+ interactAction.setLoop(THREE.LoopRepeat, Infinity)
133
+ }
150
134
 
151
- // 5. Floating Status Pin Indicator (Compact, elegant glow disk)
152
- const statusHalo = new THREE.Mesh(
153
- new THREE.RingGeometry(0.07, 0.11, 24),
154
- statusMat,
155
- )
156
- statusHalo.position.set(0, 1.7, 0)
157
- statusHalo.rotation.x = -Math.PI / 2
158
- statusHalo.userData = { entityId: entity.id }
159
- avatarRoot.add(statusHalo)
135
+ const emoteClip = THREE.AnimationClip.findByName(animations, 'emote-yes')
136
+ if (emoteClip) {
137
+ emoteAction = mixer.clipAction(emoteClip)
138
+ emoteAction.setLoop(THREE.LoopRepeat, Infinity)
139
+ }
160
140
 
161
- // 6. Realistic Procedural Animation Function
162
- const baseTorsoY = 0.6
163
- // Mutable status flags so hot-synced updates can change animation behaviour live
164
- let isWorking = entity.status === 'running' || entity.status === 'working'
165
- let isAwaiting = entity.status === 'awaiting_approval'
166
- let currentStatus = entity.status || 'idle'
167
- const breathFreq = 1.3 + (seed % 0.4)
168
- const glanceFreq = 0.22 + ((seed * 3) % 0.15)
141
+ syncAnimationActions()
142
+ }
169
143
 
170
- const animate = (_delta: number, elapsed: number) => {
171
- // Breathing cycle
172
- const breath = Math.sin(elapsed * breathFreq + seed) * 0.007
173
- torsoPlaceholder.position.y = baseTorsoY + breath
144
+ modelsContainer.add(charModel)
145
+ })
174
146
 
175
- if (realTorso) {
176
- realTorso.position.y = breath * 0.5
177
- realTorso.rotation.x = Math.sin(elapsed * breathFreq + seed) * 0.012
147
+ // 6. Standard Three.js Render Step
148
+ const animate = (delta: number, elapsed: number) => {
149
+ // A. Advance Three.js AnimationMixer
150
+ if (mixer) {
151
+ mixer.update(delta)
178
152
  }
179
153
 
180
- // Natural Gaze between dual monitors
181
- const glanceCycle = Math.sin(elapsed * glanceFreq + seed)
182
-
154
+ // B. Status Halo organic pulsing based on status
183
155
  if (isWorking) {
184
- // Active working glances & typing
185
- if (realHead) {
186
- realHead.rotation.y = glanceCycle * 0.28
187
- realHead.rotation.x = -0.04
188
- }
189
-
190
- if (realLeftArm) {
191
- realLeftArm.rotation.x = Math.PI / 2.6 + Math.sin(elapsed * 12 + seed) * 0.03
192
- }
193
- if (realRightArm) {
194
- const mouseCycle = Math.sin(elapsed * 0.9 + seed)
195
- if (mouseCycle > 0.3) {
196
- // Slide arm to mouse
197
- realRightArm.rotation.x = Math.PI / 2.8
198
- realRightArm.rotation.y = 0.18
199
- } else {
200
- // Typing on keyboard
201
- realRightArm.rotation.x = Math.PI / 2.6 + Math.cos(elapsed * 14 + seed) * 0.03
202
- realRightArm.rotation.y = 0
203
- }
204
- }
205
-
206
156
  statusHalo.scale.setScalar(1 + Math.sin(elapsed * 3.5 + seed) * 0.15)
207
157
  } else if (isAwaiting) {
208
- if (realHead) {
209
- realHead.rotation.y = Math.sin(elapsed * 0.4 + seed) * 0.15
210
- realHead.rotation.z = 0.12 // thoughtful tilt
211
- }
212
- statusHalo.scale.setScalar(1 + Math.sin(elapsed * 2) * 0.2)
158
+ statusHalo.scale.setScalar(1 + Math.sin(elapsed * 2 + seed) * 0.2)
213
159
  } else {
214
- // Idle
215
- if (realHead) {
216
- realHead.rotation.y = glanceCycle * 0.18
217
- realHead.rotation.z = 0
218
- }
219
- if (realLeftArm) realLeftArm.rotation.x = Math.PI / 2.6
220
- if (realRightArm) {
221
- realRightArm.rotation.x = Math.PI / 2.6
222
- realRightArm.rotation.y = 0
223
- }
224
160
  statusHalo.scale.setScalar(1)
225
161
  }
226
162
  }
@@ -239,6 +175,7 @@ export function createStylizedAvatar(
239
175
  isWorking = nextStatus === 'running' || nextStatus === 'working'
240
176
  isAwaiting = nextStatus === 'awaiting_approval'
241
177
  statusHalo.material = materials.getStatusGlow(nextStatus)
178
+ syncAnimationActions()
242
179
  }
243
180
 
244
181
  group.position.set(next.position[0], next.position[1], next.position[2])