@umituz/web-virtual 2.3.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.3.
|
|
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)
|
|
@@ -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
|
|
28
|
-
|
|
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
|
-
//
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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
|
-
|
|
93
|
-
|
|
94
|
-
|
|
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
|
-
//
|
|
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
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
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
|
-
|
|
143
|
-
|
|
144
|
-
|
|
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
|
-
|
|
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
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
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
|
-
|
|
162
|
-
|
|
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
|
-
|
|
171
|
-
|
|
172
|
-
const breath = Math.sin(elapsed * breathFreq + seed) * 0.007
|
|
173
|
-
torsoPlaceholder.position.y = baseTorsoY + breath
|
|
144
|
+
modelsContainer.add(charModel)
|
|
145
|
+
})
|
|
174
146
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
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
|
-
//
|
|
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
|
-
|
|
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])
|