spoint 0.1.0 → 0.1.10
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/README.md +134 -209
- package/SKILL.md +95 -0
- package/apps/environment/index.js +200 -1
- package/apps/environment/models/decorative/.gitkeep +0 -0
- package/apps/environment/models/hazards/.gitkeep +0 -0
- package/apps/environment/models/interactive/.gitkeep +0 -0
- package/apps/environment/models/structures/.gitkeep +0 -0
- package/apps/environment/smartObjects.js +114 -0
- package/apps/interactable/index.js +155 -0
- package/apps/physics-crate/index.js +15 -9
- package/apps/power-crate/index.js +18 -12
- package/apps/tps-game/$GDUPI.vrm +0 -0
- package/apps/tps-game/Cleetus.vrm +0 -0
- package/apps/tps-game/index.js +185 -27
- package/apps/world/index.js +68 -22
- package/bin/create-app.js +337 -0
- package/client/ARControls.js +301 -0
- package/client/LoadingManager.js +117 -0
- package/client/MobileControls.js +1122 -0
- package/client/anim-lib.glb +0 -0
- package/client/animation.js +306 -0
- package/client/app.js +1341 -65
- package/client/camera.js +191 -33
- package/client/createLoadingScreen.js +69 -0
- package/client/editor/bridge.js +113 -0
- package/client/editor/css/main.css +794 -0
- package/client/editor/images/rotate.svg +4 -0
- package/client/editor/images/scale.svg +4 -0
- package/client/editor/images/translate.svg +4 -0
- package/client/editor/index.html +103 -0
- package/client/editor/js/Command.js +41 -0
- package/client/editor/js/Config.js +81 -0
- package/client/editor/js/Editor.js +785 -0
- package/client/editor/js/EditorControls.js +438 -0
- package/client/editor/js/History.js +321 -0
- package/client/editor/js/Loader.js +987 -0
- package/client/editor/js/LoaderUtils.js +90 -0
- package/client/editor/js/Menubar.Add.js +510 -0
- package/client/editor/js/Menubar.Edit.js +145 -0
- package/client/editor/js/Menubar.File.js +466 -0
- package/client/editor/js/Menubar.Help.js +73 -0
- package/client/editor/js/Menubar.Status.js +51 -0
- package/client/editor/js/Menubar.View.js +183 -0
- package/client/editor/js/Menubar.js +27 -0
- package/client/editor/js/Player.js +53 -0
- package/client/editor/js/Resizer.js +58 -0
- package/client/editor/js/Script.js +503 -0
- package/client/editor/js/Selector.js +102 -0
- package/client/editor/js/Sidebar.Geometry.BoxGeometry.js +121 -0
- package/client/editor/js/Sidebar.Geometry.BufferGeometry.js +115 -0
- package/client/editor/js/Sidebar.Geometry.CapsuleGeometry.js +97 -0
- package/client/editor/js/Sidebar.Geometry.CircleGeometry.js +97 -0
- package/client/editor/js/Sidebar.Geometry.CylinderGeometry.js +121 -0
- package/client/editor/js/Sidebar.Geometry.DodecahedronGeometry.js +73 -0
- package/client/editor/js/Sidebar.Geometry.ExtrudeGeometry.js +196 -0
- package/client/editor/js/Sidebar.Geometry.IcosahedronGeometry.js +73 -0
- package/client/editor/js/Sidebar.Geometry.LatheGeometry.js +98 -0
- package/client/editor/js/Sidebar.Geometry.Modifiers.js +73 -0
- package/client/editor/js/Sidebar.Geometry.OctahedronGeometry.js +74 -0
- package/client/editor/js/Sidebar.Geometry.PlaneGeometry.js +97 -0
- package/client/editor/js/Sidebar.Geometry.RingGeometry.js +121 -0
- package/client/editor/js/Sidebar.Geometry.ShapeGeometry.js +76 -0
- package/client/editor/js/Sidebar.Geometry.SphereGeometry.js +133 -0
- package/client/editor/js/Sidebar.Geometry.TetrahedronGeometry.js +74 -0
- package/client/editor/js/Sidebar.Geometry.TorusGeometry.js +109 -0
- package/client/editor/js/Sidebar.Geometry.TorusKnotGeometry.js +121 -0
- package/client/editor/js/Sidebar.Geometry.TubeGeometry.js +135 -0
- package/client/editor/js/Sidebar.Geometry.js +332 -0
- package/client/editor/js/Sidebar.Material.BooleanProperty.js +60 -0
- package/client/editor/js/Sidebar.Material.ColorProperty.js +87 -0
- package/client/editor/js/Sidebar.Material.ConstantProperty.js +62 -0
- package/client/editor/js/Sidebar.Material.MapProperty.js +249 -0
- package/client/editor/js/Sidebar.Material.NumberProperty.js +60 -0
- package/client/editor/js/Sidebar.Material.Program.js +73 -0
- package/client/editor/js/Sidebar.Material.RangeValueProperty.js +63 -0
- package/client/editor/js/Sidebar.Material.js +751 -0
- package/client/editor/js/Sidebar.Object.Animation.js +102 -0
- package/client/editor/js/Sidebar.Object.js +898 -0
- package/client/editor/js/Sidebar.Project.App.js +165 -0
- package/client/editor/js/Sidebar.Project.Image.js +225 -0
- package/client/editor/js/Sidebar.Project.Materials.js +82 -0
- package/client/editor/js/Sidebar.Project.Renderer.js +144 -0
- package/client/editor/js/Sidebar.Project.Video.js +242 -0
- package/client/editor/js/Sidebar.Project.js +31 -0
- package/client/editor/js/Sidebar.Properties.js +73 -0
- package/client/editor/js/Sidebar.Scene.js +585 -0
- package/client/editor/js/Sidebar.Script.js +129 -0
- package/client/editor/js/Sidebar.Settings.History.js +146 -0
- package/client/editor/js/Sidebar.Settings.Shortcuts.js +175 -0
- package/client/editor/js/Sidebar.Settings.js +60 -0
- package/client/editor/js/Sidebar.js +41 -0
- package/client/editor/js/Storage.js +98 -0
- package/client/editor/js/Strings.js +2028 -0
- package/client/editor/js/Toolbar.js +84 -0
- package/client/editor/js/Viewport.Controls.js +92 -0
- package/client/editor/js/Viewport.Info.js +136 -0
- package/client/editor/js/Viewport.Pathtracer.js +91 -0
- package/client/editor/js/Viewport.ViewHelper.js +39 -0
- package/client/editor/js/Viewport.XR.js +222 -0
- package/client/editor/js/Viewport.js +900 -0
- package/client/editor/js/commands/AddObjectCommand.js +68 -0
- package/client/editor/js/commands/AddScriptCommand.js +75 -0
- package/client/editor/js/commands/Commands.js +23 -0
- package/client/editor/js/commands/MoveObjectCommand.js +111 -0
- package/client/editor/js/commands/MultiCmdsCommand.js +85 -0
- package/client/editor/js/commands/RemoveObjectCommand.js +88 -0
- package/client/editor/js/commands/RemoveScriptCommand.js +81 -0
- package/client/editor/js/commands/SetColorCommand.js +73 -0
- package/client/editor/js/commands/SetGeometryCommand.js +87 -0
- package/client/editor/js/commands/SetGeometryValueCommand.js +70 -0
- package/client/editor/js/commands/SetMaterialColorCommand.js +86 -0
- package/client/editor/js/commands/SetMaterialCommand.js +79 -0
- package/client/editor/js/commands/SetMaterialMapCommand.js +143 -0
- package/client/editor/js/commands/SetMaterialRangeCommand.js +91 -0
- package/client/editor/js/commands/SetMaterialValueCommand.js +90 -0
- package/client/editor/js/commands/SetMaterialVectorCommand.js +79 -0
- package/client/editor/js/commands/SetPositionCommand.js +84 -0
- package/client/editor/js/commands/SetRotationCommand.js +84 -0
- package/client/editor/js/commands/SetScaleCommand.js +84 -0
- package/client/editor/js/commands/SetSceneCommand.js +103 -0
- package/client/editor/js/commands/SetScriptValueCommand.js +80 -0
- package/client/editor/js/commands/SetShadowValueCommand.js +73 -0
- package/client/editor/js/commands/SetUuidCommand.js +70 -0
- package/client/editor/js/commands/SetValueCommand.js +75 -0
- package/client/editor/js/libs/acorn/acorn.js +3236 -0
- package/client/editor/js/libs/acorn/acorn_loose.js +1299 -0
- package/client/editor/js/libs/acorn/walk.js +344 -0
- package/client/editor/js/libs/app/index.html +57 -0
- package/client/editor/js/libs/app.js +251 -0
- package/client/editor/js/libs/codemirror/addon/dialog.css +32 -0
- package/client/editor/js/libs/codemirror/addon/dialog.js +163 -0
- package/client/editor/js/libs/codemirror/addon/show-hint.css +36 -0
- package/client/editor/js/libs/codemirror/addon/show-hint.js +529 -0
- package/client/editor/js/libs/codemirror/addon/tern.css +87 -0
- package/client/editor/js/libs/codemirror/addon/tern.js +750 -0
- package/client/editor/js/libs/codemirror/codemirror.css +344 -0
- package/client/editor/js/libs/codemirror/codemirror.js +9849 -0
- package/client/editor/js/libs/codemirror/mode/glsl.js +233 -0
- package/client/editor/js/libs/codemirror/mode/javascript.js +959 -0
- package/client/editor/js/libs/codemirror/theme/monokai.css +41 -0
- package/client/editor/js/libs/esprima.js +6401 -0
- package/client/editor/js/libs/jsonlint.js +453 -0
- package/client/editor/js/libs/signals.min.js +14 -0
- package/client/editor/js/libs/tern-threejs/threejs.js +5031 -0
- package/client/editor/js/libs/ternjs/comment.js +87 -0
- package/client/editor/js/libs/ternjs/def.js +588 -0
- package/client/editor/js/libs/ternjs/doc_comment.js +401 -0
- package/client/editor/js/libs/ternjs/infer.js +1635 -0
- package/client/editor/js/libs/ternjs/polyfill.js +80 -0
- package/client/editor/js/libs/ternjs/signal.js +26 -0
- package/client/editor/js/libs/ternjs/tern.js +993 -0
- package/client/editor/js/libs/ui.js +1346 -0
- package/client/editor/js/libs/ui.three.js +855 -0
- package/client/facial-animation.js +455 -0
- package/client/index.html +7 -4
- package/client/loading.css +147 -0
- package/client/loading.html +25 -0
- package/client/style.css +251 -0
- package/package.json +7 -3
- package/server.js +9 -1
- package/src/apps/AppContext.js +1 -1
- package/src/apps/AppLoader.js +50 -37
- package/src/apps/AppRuntime.js +32 -8
- package/src/client/InputHandler.js +233 -0
- package/src/client/JitterBuffer.js +207 -0
- package/src/client/KalmanFilter.js +125 -0
- package/src/client/MessageHandler.js +101 -0
- package/src/client/PhysicsNetworkClient.js +141 -68
- package/src/client/ReconnectManager.js +62 -0
- package/src/client/SmoothInterpolation.js +127 -0
- package/src/client/SnapshotProcessor.js +144 -0
- package/src/connection/ConnectionManager.js +21 -3
- package/src/connection/SessionStore.js +13 -3
- package/src/index.client.js +4 -6
- package/src/netcode/EventLog.js +29 -15
- package/src/netcode/LagCompensator.js +25 -26
- package/src/netcode/NetworkState.js +4 -1
- package/src/netcode/PhysicsIntegration.js +20 -6
- package/src/netcode/PlayerManager.js +10 -2
- package/src/netcode/SnapshotEncoder.js +66 -19
- package/src/netcode/TickSystem.js +13 -4
- package/src/physics/World.js +66 -13
- package/src/protocol/msgpack.js +90 -63
- package/src/sdk/ReloadHandlers.js +12 -2
- package/src/sdk/ReloadManager.js +5 -0
- package/src/sdk/ServerHandlers.js +50 -11
- package/src/sdk/StaticHandler.js +22 -6
- package/src/sdk/TickHandler.js +101 -34
- package/src/sdk/scaffold.js +28 -0
- package/src/sdk/server.js +59 -33
- package/src/shared/movement.js +2 -1
- package/src/spatial/Octree.js +5 -0
- package/apps/interactive-door/index.js +0 -33
- package/apps/patrol-npc/index.js +0 -37
- package/src/connection/QualityMonitor.js +0 -46
- package/src/debug/StateInspector.js +0 -42
- package/src/index.js +0 -1
- package/src/index.server.js +0 -27
- package/src/protocol/Codec.js +0 -60
- package/src/protocol/SequenceTracker.js +0 -71
- package/src/sdk/ClientMessageHandler.js +0 -80
- package/src/sdk/client.js +0 -122
- package/world/kaira.glb +0 -0
- package/world/schwust.glb +0 -0
|
@@ -0,0 +1,455 @@
|
|
|
1
|
+
import * as THREE from 'three'
|
|
2
|
+
|
|
3
|
+
const MAGIC = 0x4146414E
|
|
4
|
+
const ARKIT_NAMES = [
|
|
5
|
+
'browInnerUp', 'browDownLeft', 'browDownRight', 'browOuterUpLeft', 'browOuterUpRight',
|
|
6
|
+
'eyeLookUpLeft', 'eyeLookUpRight', 'eyeLookDownLeft', 'eyeLookDownRight',
|
|
7
|
+
'eyeLookInLeft', 'eyeLookInRight', 'eyeLookOutLeft', 'eyeLookOutRight',
|
|
8
|
+
'eyeBlinkLeft', 'eyeBlinkRight', 'eyeSquintLeft', 'eyeSquintRight',
|
|
9
|
+
'eyeWideLeft', 'eyeWideRight', 'cheekPuff', 'cheekSquintLeft', 'cheekSquintRight',
|
|
10
|
+
'noseSneerLeft', 'noseSneerRight', 'jawOpen', 'jawForward', 'jawLeft', 'jawRight',
|
|
11
|
+
'mouthFunnel', 'mouthPucker', 'mouthLeft', 'mouthRight',
|
|
12
|
+
'mouthRollUpper', 'mouthRollLower', 'mouthShrugUpper', 'mouthShrugLower',
|
|
13
|
+
'mouthOpen', 'mouthClose', 'mouthSmileLeft', 'mouthSmileRight',
|
|
14
|
+
'mouthFrownLeft', 'mouthFrownRight', 'mouthDimpleLeft', 'mouthDimpleRight',
|
|
15
|
+
'mouthUpperUpLeft', 'mouthUpperUpRight', 'mouthLowerDownLeft', 'mouthLowerDownRight',
|
|
16
|
+
'mouthPressLeft', 'mouthPressRight', 'mouthStretchLeft', 'mouthStretchRight'
|
|
17
|
+
]
|
|
18
|
+
|
|
19
|
+
function detectVRMVersion(vrm) {
|
|
20
|
+
if (!vrm) return '1'
|
|
21
|
+
if (vrm.meta?.version === '0' || vrm.meta?.specVersion?.startsWith('0')) return '0'
|
|
22
|
+
if (vrm.expressionManager) {
|
|
23
|
+
const names = vrm.expressionManager.expressions.map(e => e.expressionName)
|
|
24
|
+
if (names.includes('fun') || names.includes('sorrow')) return '0'
|
|
25
|
+
if (names.includes('happy') || names.includes('sad')) return '1'
|
|
26
|
+
}
|
|
27
|
+
return '1'
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function clamp(v, lo = 0, hi = 1) {
|
|
31
|
+
return Math.max(lo, Math.min(hi, v))
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function mapVisemes(blendshapes) {
|
|
35
|
+
const {
|
|
36
|
+
jawOpen = 0, mouthClose = 0, mouthFunnel = 0, mouthPucker = 0,
|
|
37
|
+
mouthSmileLeft = 0, mouthSmileRight = 0, mouthFrownLeft = 0, mouthFrownRight = 0,
|
|
38
|
+
mouthUpperUpLeft = 0, mouthUpperUpRight = 0, mouthLowerDownLeft = 0, mouthLowerDownRight = 0,
|
|
39
|
+
mouthStretchLeft = 0, mouthStretchRight = 0, mouthRollUpper = 0, mouthRollLower = 0,
|
|
40
|
+
mouthPressLeft = 0, mouthPressRight = 0, mouthShrugUpper = 0, mouthShrugLower = 0,
|
|
41
|
+
mouthDimpleLeft = 0, mouthDimpleRight = 0, mouthLeft = 0, mouthRight = 0
|
|
42
|
+
} = blendshapes
|
|
43
|
+
|
|
44
|
+
const smile = Math.max(mouthSmileLeft, mouthSmileRight)
|
|
45
|
+
const stretch = Math.max(mouthStretchLeft, mouthStretchRight)
|
|
46
|
+
const upperUp = Math.max(mouthUpperUpLeft, mouthUpperUpRight)
|
|
47
|
+
const lowerDown = Math.max(mouthLowerDownLeft, mouthLowerDownRight)
|
|
48
|
+
const frown = Math.max(mouthFrownLeft, mouthFrownRight)
|
|
49
|
+
|
|
50
|
+
const aa = clamp(jawOpen * 0.7 + lowerDown * 0.3)
|
|
51
|
+
const ih = clamp(upperUp * 0.6 + stretch * 0.4)
|
|
52
|
+
const ou = clamp(mouthFunnel * 0.5 + mouthPucker * 0.5)
|
|
53
|
+
const ee = clamp(stretch * 0.7 + (1 - jawOpen) * 0.3)
|
|
54
|
+
const oh = clamp(mouthPucker * 0.4 + jawOpen * 0.4 + mouthFunnel * 0.2)
|
|
55
|
+
|
|
56
|
+
return { aa, ih, ou, ee, oh }
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function mapEyes(blendshapes) {
|
|
60
|
+
const {
|
|
61
|
+
eyeBlinkLeft = 0, eyeBlinkRight = 0, eyeSquintLeft = 0, eyeSquintRight = 0,
|
|
62
|
+
eyeWideLeft = 0, eyeWideRight = 0, eyeLookUpLeft = 0, eyeLookUpRight = 0,
|
|
63
|
+
eyeLookDownLeft = 0, eyeLookDownRight = 0, eyeLookInLeft = 0, eyeLookInRight = 0,
|
|
64
|
+
eyeLookOutLeft = 0, eyeLookOutRight = 0
|
|
65
|
+
} = blendshapes
|
|
66
|
+
|
|
67
|
+
return {
|
|
68
|
+
blinkLeft: clamp(eyeBlinkLeft + eyeSquintLeft * 0.3),
|
|
69
|
+
blinkRight: clamp(eyeBlinkRight + eyeSquintRight * 0.3),
|
|
70
|
+
blink: clamp((eyeBlinkLeft + eyeBlinkRight) / 2),
|
|
71
|
+
lookUp: clamp(Math.max(eyeLookUpLeft, eyeLookUpRight)),
|
|
72
|
+
lookDown: clamp(Math.max(eyeLookDownLeft, eyeLookDownRight)),
|
|
73
|
+
lookLeft: clamp(Math.max(eyeLookInLeft, eyeLookOutRight)),
|
|
74
|
+
lookRight: clamp(Math.max(eyeLookInRight, eyeLookOutLeft))
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function mapBrows(blendshapes) {
|
|
79
|
+
const {
|
|
80
|
+
browInnerUp = 0, browDownLeft = 0, browDownRight = 0,
|
|
81
|
+
browOuterUpLeft = 0, browOuterUpRight = 0
|
|
82
|
+
} = blendshapes
|
|
83
|
+
|
|
84
|
+
return {
|
|
85
|
+
browInnerUp,
|
|
86
|
+
browDown: Math.max(browDownLeft, browDownRight),
|
|
87
|
+
browOuterUp: Math.max(browOuterUpLeft, browOuterUpRight)
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function mapEmotionsV0(blendshapes) {
|
|
92
|
+
const {
|
|
93
|
+
mouthSmileLeft = 0, mouthSmileRight = 0, mouthFrownLeft = 0, mouthFrownRight = 0,
|
|
94
|
+
browInnerUp = 0, browDownLeft = 0, browDownRight = 0, browOuterUpLeft = 0, browOuterUpRight = 0,
|
|
95
|
+
cheekPuff = 0, eyeSquintLeft = 0, eyeSquintRight = 0, noseSneerLeft = 0, noseSneerRight = 0,
|
|
96
|
+
jawOpen = 0, mouthFunnel = 0, mouthPucker = 0, eyeWideLeft = 0, eyeWideRight = 0
|
|
97
|
+
} = blendshapes
|
|
98
|
+
|
|
99
|
+
const smile = Math.max(mouthSmileLeft, mouthSmileRight)
|
|
100
|
+
const frown = Math.max(mouthFrownLeft, mouthFrownRight)
|
|
101
|
+
const browUp = browInnerUp + Math.max(browOuterUpLeft, browOuterUpRight)
|
|
102
|
+
const browDown = Math.max(browDownLeft, browDownRight)
|
|
103
|
+
const squint = Math.max(eyeSquintLeft, eyeSquintRight)
|
|
104
|
+
const wide = Math.max(eyeWideLeft, eyeWideRight)
|
|
105
|
+
const sneer = Math.max(noseSneerLeft, noseSneerRight)
|
|
106
|
+
|
|
107
|
+
const joy = clamp(smile * 0.8 + (1 - browDown) * 0.2)
|
|
108
|
+
const fun = clamp(smile * 0.6 + cheekPuff * 0.3 + squint * 0.1)
|
|
109
|
+
const angry = clamp(browDown * 0.6 + sneer * 0.3 + frown * 0.1)
|
|
110
|
+
const sorrow = clamp(frown * 0.5 + browDown * 0.3 + (1 - smile) * 0.2)
|
|
111
|
+
|
|
112
|
+
return { joy, angry, sorrow, fun }
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function mapEmotionsV1(blendshapes) {
|
|
116
|
+
const {
|
|
117
|
+
mouthSmileLeft = 0, mouthSmileRight = 0, mouthFrownLeft = 0, mouthFrownRight = 0,
|
|
118
|
+
browInnerUp = 0, browDownLeft = 0, browDownRight = 0, browOuterUpLeft = 0, browOuterUpRight = 0,
|
|
119
|
+
cheekPuff = 0, eyeSquintLeft = 0, eyeSquintRight = 0, noseSneerLeft = 0, noseSneerRight = 0,
|
|
120
|
+
jawOpen = 0, mouthFunnel = 0, mouthPucker = 0, eyeWideLeft = 0, eyeWideRight = 0
|
|
121
|
+
} = blendshapes
|
|
122
|
+
|
|
123
|
+
const smile = Math.max(mouthSmileLeft, mouthSmileRight)
|
|
124
|
+
const frown = Math.max(mouthFrownLeft, mouthFrownRight)
|
|
125
|
+
const browUp = browInnerUp + Math.max(browOuterUpLeft, browOuterUpRight)
|
|
126
|
+
const browDown = Math.max(browDownLeft, browDownRight)
|
|
127
|
+
const squint = Math.max(eyeSquintLeft, eyeSquintRight)
|
|
128
|
+
const wide = Math.max(eyeWideLeft, eyeWideRight)
|
|
129
|
+
const sneer = Math.max(noseSneerLeft, noseSneerRight)
|
|
130
|
+
|
|
131
|
+
const happy = clamp(smile * 0.9 + squint * 0.1)
|
|
132
|
+
const sad = clamp(frown * 0.6 + browDown * 0.3 + (1 - smile) * 0.1)
|
|
133
|
+
const angry = clamp(browDown * 0.5 + sneer * 0.3 + frown * 0.2)
|
|
134
|
+
const relaxed = clamp((1 - browDown) * 0.5 + smile * 0.3 + cheekPuff * 0.2)
|
|
135
|
+
const surprised = clamp(browUp * 0.6 + wide * 0.3 + jawOpen * 0.1)
|
|
136
|
+
|
|
137
|
+
return { happy, sad, angry, relaxed, surprised }
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export class AnimationReader {
|
|
141
|
+
constructor() {
|
|
142
|
+
this.fps = 30
|
|
143
|
+
this.numBlendshapes = 0
|
|
144
|
+
this.numFrames = 0
|
|
145
|
+
this.names = ARKIT_NAMES
|
|
146
|
+
this.frames = []
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
fromBuffer(buf) {
|
|
150
|
+
let offset = 0
|
|
151
|
+
const view = new DataView(buf instanceof ArrayBuffer ? buf : buf.buffer)
|
|
152
|
+
|
|
153
|
+
const magic = view.getUint32(offset, true); offset += 4
|
|
154
|
+
if (magic !== MAGIC) throw new Error('Invalid animation file')
|
|
155
|
+
|
|
156
|
+
const version = view.getUint8(offset); offset += 1
|
|
157
|
+
if (version < 1 || version > 2) throw new Error(`Unsupported version: ${version}`)
|
|
158
|
+
|
|
159
|
+
this.fps = view.getUint8(offset); offset += 1
|
|
160
|
+
this.numBlendshapes = view.getUint8(offset); offset += 1
|
|
161
|
+
offset += 1
|
|
162
|
+
this.numFrames = view.getUint32(offset, true); offset += 4
|
|
163
|
+
|
|
164
|
+
if (version === 1) {
|
|
165
|
+
this.names = []
|
|
166
|
+
for (let i = 0; i < this.numBlendshapes; i++) {
|
|
167
|
+
const len = view.getUint8(offset++)
|
|
168
|
+
this.names.push(new TextDecoder().decode(new Uint8Array(buf, offset, len)))
|
|
169
|
+
offset += len
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
this.frames = []
|
|
174
|
+
for (let f = 0; f < this.numFrames; f++) {
|
|
175
|
+
const frame = {}
|
|
176
|
+
for (let i = 0; i < this.numBlendshapes; i++) {
|
|
177
|
+
frame[this.names[i]] = view.getUint8(offset++) / 255
|
|
178
|
+
}
|
|
179
|
+
this.frames.push({ time: f / this.fps, blendshapes: frame })
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
return this
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
getFrame(index) {
|
|
186
|
+
return this.frames[Math.max(0, Math.min(index, this.frames.length - 1))]
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
getFrameAtTime(time) {
|
|
190
|
+
return this.getFrame(Math.floor(time * this.fps))
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
export class FacialAnimationPlayer {
|
|
195
|
+
constructor(vrm, options = {}) {
|
|
196
|
+
this.vrm = vrm
|
|
197
|
+
this.expressionManager = vrm.expressionManager
|
|
198
|
+
this.vrmVersion = detectVRMVersion(vrm)
|
|
199
|
+
this.animation = null
|
|
200
|
+
this.audio = null
|
|
201
|
+
this.isPlaying = false
|
|
202
|
+
this.startTime = 0
|
|
203
|
+
this.currentTime = 0
|
|
204
|
+
this.onComplete = null
|
|
205
|
+
this.volume = options.volume ?? 1.0
|
|
206
|
+
this.availableExpressions = new Set()
|
|
207
|
+
this.storedExpressions = new Map()
|
|
208
|
+
this.lastApplied = new Map()
|
|
209
|
+
|
|
210
|
+
if (this.expressionManager) {
|
|
211
|
+
this.expressionManager.expressions.forEach(e => {
|
|
212
|
+
this.availableExpressions.add(e.expressionName)
|
|
213
|
+
})
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
loadAnimation(buffer) {
|
|
218
|
+
this.animation = new AnimationReader().fromBuffer(buffer)
|
|
219
|
+
return this.animation
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
loadAudio(buffer, mimeType = 'audio/mpeg') {
|
|
223
|
+
this.audio = new Audio()
|
|
224
|
+
this.audio.src = URL.createObjectURL(new Blob([buffer], { type: mimeType }))
|
|
225
|
+
this.audio.volume = this.volume
|
|
226
|
+
return new Promise((resolve, reject) => {
|
|
227
|
+
this.audio.oncanplaythrough = () => resolve(this)
|
|
228
|
+
this.audio.onerror = () => reject(new Error('Failed to load audio'))
|
|
229
|
+
})
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
async load(animBuffer, audioBuffer, mimeType) {
|
|
233
|
+
if (animBuffer) this.loadAnimation(animBuffer)
|
|
234
|
+
if (audioBuffer) await this.loadAudio(audioBuffer, mimeType)
|
|
235
|
+
return this
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
play() {
|
|
239
|
+
if (!this.animation) return
|
|
240
|
+
|
|
241
|
+
this.storedExpressions.clear()
|
|
242
|
+
this.lastApplied.clear()
|
|
243
|
+
|
|
244
|
+
if (this.expressionManager) {
|
|
245
|
+
for (const name of ['blink', 'blinkLeft', 'blinkRight']) {
|
|
246
|
+
if (this.availableExpressions.has(name)) {
|
|
247
|
+
const val = this.expressionManager.getValue(name)
|
|
248
|
+
if (val > 0) this.storedExpressions.set(name, val)
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
this.isPlaying = true
|
|
254
|
+
this.startTime = performance.now()
|
|
255
|
+
|
|
256
|
+
if (this.audio) {
|
|
257
|
+
this.audio.currentTime = 0
|
|
258
|
+
this.audio.play().catch(() => {})
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
stop() {
|
|
263
|
+
this.isPlaying = false
|
|
264
|
+
if (this.audio) {
|
|
265
|
+
this.audio.pause()
|
|
266
|
+
this.audio.currentTime = 0
|
|
267
|
+
}
|
|
268
|
+
this.resetExpressions()
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
resetExpressions() {
|
|
272
|
+
if (!this.expressionManager) return
|
|
273
|
+
|
|
274
|
+
for (const name of this.availableExpressions) {
|
|
275
|
+
if (this.storedExpressions.has(name)) {
|
|
276
|
+
this.expressionManager.setValue(name, this.storedExpressions.get(name))
|
|
277
|
+
} else {
|
|
278
|
+
this.expressionManager.setValue(name, 0)
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
this.lastApplied.clear()
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
update(dt) {
|
|
285
|
+
if (!this.isPlaying || !this.animation) return
|
|
286
|
+
|
|
287
|
+
const elapsed = (performance.now() - this.startTime) / 1000
|
|
288
|
+
this.currentTime = elapsed
|
|
289
|
+
|
|
290
|
+
const frame = this.animation.getFrameAtTime(elapsed)
|
|
291
|
+
if (!frame) return
|
|
292
|
+
|
|
293
|
+
this.applyFrame(frame.blendshapes)
|
|
294
|
+
|
|
295
|
+
if (elapsed >= this.animation.frames.length / this.animation.fps) {
|
|
296
|
+
this.isPlaying = false
|
|
297
|
+
if (this.onComplete) this.onComplete()
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
applyFrame(blendshapes) {
|
|
302
|
+
if (!this.expressionManager) return
|
|
303
|
+
|
|
304
|
+
const values = new Map()
|
|
305
|
+
const has = (name) => this.availableExpressions.has(name)
|
|
306
|
+
const set = (name, val) => {
|
|
307
|
+
if (has(name) && val > 0.001) values.set(name, clamp(val))
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
const visemes = mapVisemes(blendshapes)
|
|
311
|
+
set('aa', visemes.aa)
|
|
312
|
+
set('ih', visemes.ih)
|
|
313
|
+
set('ou', visemes.ou)
|
|
314
|
+
set('ee', visemes.ee)
|
|
315
|
+
set('oh', visemes.oh)
|
|
316
|
+
|
|
317
|
+
const eyes = mapEyes(blendshapes)
|
|
318
|
+
set('blinkLeft', eyes.blinkLeft)
|
|
319
|
+
set('blinkRight', eyes.blinkRight)
|
|
320
|
+
set('blink', eyes.blink)
|
|
321
|
+
set('lookUp', eyes.lookUp)
|
|
322
|
+
set('lookDown', eyes.lookDown)
|
|
323
|
+
set('lookLeft', eyes.lookLeft)
|
|
324
|
+
set('lookRight', eyes.lookRight)
|
|
325
|
+
|
|
326
|
+
if (this.vrmVersion === '0') {
|
|
327
|
+
const emotions = mapEmotionsV0(blendshapes)
|
|
328
|
+
set('joy', emotions.joy)
|
|
329
|
+
set('fun', emotions.fun)
|
|
330
|
+
set('angry', emotions.angry)
|
|
331
|
+
set('sorrow', emotions.sorrow)
|
|
332
|
+
} else {
|
|
333
|
+
const emotions = mapEmotionsV1(blendshapes)
|
|
334
|
+
set('happy', emotions.happy)
|
|
335
|
+
set('sad', emotions.sad)
|
|
336
|
+
set('angry', emotions.angry)
|
|
337
|
+
set('relaxed', emotions.relaxed)
|
|
338
|
+
set('surprised', emotions.surprised)
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
for (const [name, val] of values) {
|
|
342
|
+
if (!this.storedExpressions.has(name)) {
|
|
343
|
+
this.expressionManager.setValue(name, val)
|
|
344
|
+
this.lastApplied.set(name, val)
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
for (const name of this.lastApplied.keys()) {
|
|
349
|
+
if (!values.has(name)) {
|
|
350
|
+
const last = this.lastApplied.get(name)
|
|
351
|
+
const decayed = last * 0.6
|
|
352
|
+
if (decayed < 0.01) {
|
|
353
|
+
this.expressionManager.setValue(name, 0)
|
|
354
|
+
this.lastApplied.delete(name)
|
|
355
|
+
} else {
|
|
356
|
+
this.expressionManager.setValue(name, decayed)
|
|
357
|
+
this.lastApplied.set(name, decayed)
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
getDuration() {
|
|
364
|
+
return this.animation ? this.animation.frames.length / this.animation.fps : 0
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
setVolume(v) {
|
|
368
|
+
this.volume = Math.max(0, Math.min(1, v))
|
|
369
|
+
if (this.audio) this.audio.volume = this.volume
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
dispose() {
|
|
373
|
+
this.stop()
|
|
374
|
+
if (this.audio) {
|
|
375
|
+
URL.revokeObjectURL(this.audio.src)
|
|
376
|
+
this.audio = null
|
|
377
|
+
}
|
|
378
|
+
this.animation = null
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
const playerFacialPlayers = new Map()
|
|
383
|
+
|
|
384
|
+
export function initFacialSystem(engine) {
|
|
385
|
+
engine.facial = {
|
|
386
|
+
async load(playerId, animUrl, audioUrl) {
|
|
387
|
+
const vrm = engine.playerVrms?.get(playerId)
|
|
388
|
+
if (!vrm) return null
|
|
389
|
+
|
|
390
|
+
let player = playerFacialPlayers.get(playerId)
|
|
391
|
+
if (!player) {
|
|
392
|
+
player = new FacialAnimationPlayer(vrm)
|
|
393
|
+
playerFacialPlayers.set(playerId, player)
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
const [animResp, audioResp] = await Promise.all([
|
|
397
|
+
fetch(animUrl).then(r => r.ok ? r.arrayBuffer() : null).catch(() => null),
|
|
398
|
+
fetch(audioUrl).then(r => r.ok ? r.arrayBuffer() : null).catch(() => null)
|
|
399
|
+
])
|
|
400
|
+
|
|
401
|
+
if (!animResp) return null
|
|
402
|
+
|
|
403
|
+
await player.load(animResp, audioResp)
|
|
404
|
+
return player
|
|
405
|
+
},
|
|
406
|
+
|
|
407
|
+
play(playerId) {
|
|
408
|
+
const player = playerFacialPlayers.get(playerId)
|
|
409
|
+
if (player) player.play()
|
|
410
|
+
return player
|
|
411
|
+
},
|
|
412
|
+
|
|
413
|
+
stop(playerId) {
|
|
414
|
+
const player = playerFacialPlayers.get(playerId)
|
|
415
|
+
if (player) player.stop()
|
|
416
|
+
return player
|
|
417
|
+
},
|
|
418
|
+
|
|
419
|
+
async playNow(playerId, animUrl, audioUrl) {
|
|
420
|
+
const player = await this.load(playerId, animUrl, audioUrl)
|
|
421
|
+
if (player) player.play()
|
|
422
|
+
return player
|
|
423
|
+
},
|
|
424
|
+
|
|
425
|
+
getPlayer(playerId) {
|
|
426
|
+
return playerFacialPlayers.get(playerId)
|
|
427
|
+
},
|
|
428
|
+
|
|
429
|
+
isPlaying(playerId) {
|
|
430
|
+
return playerFacialPlayers.get(playerId)?.isPlaying ?? false
|
|
431
|
+
},
|
|
432
|
+
|
|
433
|
+
update(dt) {
|
|
434
|
+
for (const player of playerFacialPlayers.values()) {
|
|
435
|
+
player.update(dt)
|
|
436
|
+
}
|
|
437
|
+
},
|
|
438
|
+
|
|
439
|
+
dispose(playerId) {
|
|
440
|
+
const player = playerFacialPlayers.get(playerId)
|
|
441
|
+
if (player) {
|
|
442
|
+
player.dispose()
|
|
443
|
+
playerFacialPlayers.delete(playerId)
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
return engine.facial
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
export function createFacialPlayer(vrm, options = {}) {
|
|
452
|
+
return new FacialAnimationPlayer(vrm, options)
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
export default FacialAnimationPlayer
|
package/client/index.html
CHANGED
|
@@ -2,16 +2,19 @@
|
|
|
2
2
|
<html lang="en">
|
|
3
3
|
<head>
|
|
4
4
|
<meta charset="UTF-8">
|
|
5
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
-
<
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
|
|
6
|
+
<meta name="apple-mobile-web-app-capable" content="yes">
|
|
7
|
+
<meta name="mobile-web-app-capable" content="yes">
|
|
8
|
+
<title>Spawnpoint</title>
|
|
7
9
|
<link rel="stylesheet" href="/style.css">
|
|
8
10
|
<script type="importmap">
|
|
9
11
|
{
|
|
10
12
|
"imports": {
|
|
11
13
|
"three": "https://esm.sh/three@0.171.0",
|
|
12
14
|
"three/addons/": "https://esm.sh/three@0.171.0/examples/jsm/",
|
|
13
|
-
"
|
|
14
|
-
"webjsx
|
|
15
|
+
"@pixiv/three-vrm": "https://esm.sh/@pixiv/three-vrm@3?external=three",
|
|
16
|
+
"webjsx": "https://esm.sh/webjsx@0.0.73",
|
|
17
|
+
"webjsx/jsx-runtime": "https://esm.sh/webjsx@0.0.73/jsx-runtime"
|
|
15
18
|
}
|
|
16
19
|
}
|
|
17
20
|
</script>
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
.loading-overlay {
|
|
2
|
+
position: fixed;
|
|
3
|
+
top: 0;
|
|
4
|
+
left: 0;
|
|
5
|
+
width: 100%;
|
|
6
|
+
height: 100%;
|
|
7
|
+
background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
|
|
8
|
+
display: flex;
|
|
9
|
+
align-items: center;
|
|
10
|
+
justify-content: center;
|
|
11
|
+
z-index: 9999;
|
|
12
|
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.loading-container {
|
|
16
|
+
text-align: center;
|
|
17
|
+
color: white;
|
|
18
|
+
max-width: 400px;
|
|
19
|
+
width: 90%;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
.loading-header h1 {
|
|
23
|
+
margin: 0 0 10px 0;
|
|
24
|
+
font-size: 2.5rem;
|
|
25
|
+
font-weight: 700;
|
|
26
|
+
letter-spacing: 2px;
|
|
27
|
+
background: linear-gradient(135deg, #00d4ff, #0099ff);
|
|
28
|
+
-webkit-background-clip: text;
|
|
29
|
+
-webkit-text-fill-color: transparent;
|
|
30
|
+
background-clip: text;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.loading-stage-text {
|
|
34
|
+
margin: 0;
|
|
35
|
+
font-size: 0.95rem;
|
|
36
|
+
opacity: 0.8;
|
|
37
|
+
color: #a0a0a0;
|
|
38
|
+
min-height: 1.5rem;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
.loading-progress-wrapper {
|
|
42
|
+
margin: 30px 0;
|
|
43
|
+
position: relative;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
.loading-progress-bar {
|
|
47
|
+
width: 100%;
|
|
48
|
+
height: 6px;
|
|
49
|
+
background: rgba(255, 255, 255, 0.1);
|
|
50
|
+
border-radius: 3px;
|
|
51
|
+
overflow: hidden;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
.loading-progress-fill {
|
|
55
|
+
height: 100%;
|
|
56
|
+
background: linear-gradient(90deg, #00d4ff, #0099ff);
|
|
57
|
+
width: 0%;
|
|
58
|
+
transition: width 0.2s ease-out;
|
|
59
|
+
box-shadow: 0 0 10px rgba(0, 212, 255, 0.5);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
.loading-percent {
|
|
63
|
+
position: absolute;
|
|
64
|
+
right: 0;
|
|
65
|
+
top: -24px;
|
|
66
|
+
font-size: 0.85rem;
|
|
67
|
+
font-weight: 600;
|
|
68
|
+
min-width: 40px;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
.loading-details {
|
|
72
|
+
font-size: 0.75rem;
|
|
73
|
+
color: #808080;
|
|
74
|
+
margin-top: 15px;
|
|
75
|
+
min-height: 1rem;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
.loading-details .loading-current,
|
|
79
|
+
.loading-details .loading-total {
|
|
80
|
+
color: #00d4ff;
|
|
81
|
+
font-weight: 600;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
.loading-spinner {
|
|
85
|
+
display: flex;
|
|
86
|
+
justify-content: center;
|
|
87
|
+
gap: 8px;
|
|
88
|
+
margin-top: 30px;
|
|
89
|
+
height: 12px;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
.spinner-dot {
|
|
93
|
+
width: 8px;
|
|
94
|
+
height: 8px;
|
|
95
|
+
border-radius: 50%;
|
|
96
|
+
background: #00d4ff;
|
|
97
|
+
opacity: 0.4;
|
|
98
|
+
animation: spin-bounce 1.2s infinite ease-in-out;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
.spinner-dot:nth-child(1) {
|
|
102
|
+
animation-delay: -0.32s;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
.spinner-dot:nth-child(2) {
|
|
106
|
+
animation-delay: -0.16s;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
@keyframes spin-bounce {
|
|
110
|
+
0%, 80%, 100% {
|
|
111
|
+
opacity: 0.4;
|
|
112
|
+
transform: scale(0.8);
|
|
113
|
+
}
|
|
114
|
+
40% {
|
|
115
|
+
opacity: 1;
|
|
116
|
+
transform: scale(1);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
.loading-overlay.fade-out {
|
|
121
|
+
animation: fade-out-animation 0.5s ease-out forwards;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
@keyframes fade-out-animation {
|
|
125
|
+
from {
|
|
126
|
+
opacity: 1;
|
|
127
|
+
visibility: visible;
|
|
128
|
+
}
|
|
129
|
+
to {
|
|
130
|
+
opacity: 0;
|
|
131
|
+
visibility: hidden;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
@media (max-width: 640px) {
|
|
136
|
+
.loading-header h1 {
|
|
137
|
+
font-size: 1.8rem;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
.loading-stage-text {
|
|
141
|
+
font-size: 0.85rem;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
.loading-details {
|
|
145
|
+
font-size: 0.7rem;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
<div id="loading-overlay" class="loading-overlay">
|
|
2
|
+
<div class="loading-container">
|
|
3
|
+
<div class="loading-header">
|
|
4
|
+
<h1>Spawnpoint</h1>
|
|
5
|
+
<p class="loading-stage-text">Connecting...</p>
|
|
6
|
+
</div>
|
|
7
|
+
|
|
8
|
+
<div class="loading-progress-wrapper">
|
|
9
|
+
<div class="loading-progress-bar">
|
|
10
|
+
<div class="loading-progress-fill"></div>
|
|
11
|
+
</div>
|
|
12
|
+
<div class="loading-percent">0%</div>
|
|
13
|
+
</div>
|
|
14
|
+
|
|
15
|
+
<div class="loading-details">
|
|
16
|
+
<span class="loading-current">0</span> / <span class="loading-total">0</span> bytes
|
|
17
|
+
</div>
|
|
18
|
+
|
|
19
|
+
<div class="loading-spinner">
|
|
20
|
+
<div class="spinner-dot"></div>
|
|
21
|
+
<div class="spinner-dot"></div>
|
|
22
|
+
<div class="spinner-dot"></div>
|
|
23
|
+
</div>
|
|
24
|
+
</div>
|
|
25
|
+
</div>
|