@nice2dev/ui-3d 1.3.14 → 1.3.16
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/CHANGELOG.md +13 -0
- package/dist/cjs/collaborative/collaborativeScene.js +160 -206
- package/dist/cjs/core/editorAsk.js +51 -41
- package/dist/cjs/core/i18n.js +13 -14
- package/dist/cjs/core/threeCompat.js +29 -42
- package/dist/cjs/dance/DanceBridge.js +148 -177
- package/dist/cjs/dance/DanceScoreEngine.js +209 -221
- package/dist/cjs/dance/PoseDetector.js +302 -275
- package/dist/cjs/index.js +110 -113
- package/dist/cjs/material/MaterialEditor.module.css.js +242 -5
- package/dist/cjs/material/NiceMaterialEditor.js +1213 -757
- package/dist/cjs/material/materialEditorTypes.js +35 -49
- package/dist/cjs/material/materialEditorUtils.js +684 -747
- package/dist/cjs/material/materialNodeDefinitions.js +1411 -1459
- package/dist/cjs/model/ModelEditor.js +90 -40
- package/dist/cjs/model/ModelEditor.module.css.js +257 -5
- package/dist/cjs/model/ModelEditorLeftPanel.js +126 -47
- package/dist/cjs/model/ModelEditorMenuBar.js +359 -32
- package/dist/cjs/model/ModelEditorRightPanel.js +647 -131
- package/dist/cjs/model/ModelEditorSubComponents.js +277 -112
- package/dist/cjs/model/ModelEditorTimeline.js +232 -34
- package/dist/cjs/model/ModelEditorToolbar.js +170 -14
- package/dist/cjs/model/ModelEditorViewport.js +231 -39
- package/dist/cjs/model/ModelViewer.js +388 -63
- package/dist/cjs/model/ModelViewer.module.css.js +77 -5
- package/dist/cjs/model/NiceArmatureEditor.js +473 -274
- package/dist/cjs/model/NiceMorphTargetEditor.js +333 -227
- package/dist/cjs/model/NiceOctree.js +372 -320
- package/dist/cjs/model/NicePhysicsSimulation.js +528 -298
- package/dist/cjs/model/NiceProceduralGeometry.js +673 -300
- package/dist/cjs/model/NiceTerrainEditor.js +595 -385
- package/dist/cjs/model/NiceWeightPainter.js +384 -261
- package/dist/cjs/model/NiceXRPreview.js +385 -308
- package/dist/cjs/model/cadModeUtils.js +103 -106
- package/dist/cjs/model/editorShortcuts.js +171 -194
- package/dist/cjs/model/modelEditorTypes.js +100 -118
- package/dist/cjs/model/modelEditorUtils.js +1061 -1146
- package/dist/cjs/model/simsModeUtils.js +1023 -1053
- package/dist/cjs/model/useModelEditor.js +1977 -1933
- package/dist/cjs/model/useModelViewer.js +633 -665
- package/dist/cjs/nice2dev-ui-3d.css +1 -1
- package/dist/cjs/particle/NiceParticleEditor.js +1186 -571
- package/dist/cjs/particle/ParticleEditor.module.css.js +122 -5
- package/dist/cjs/particle/particleEditorTypes.js +62 -70
- package/dist/cjs/particle/particleEditorUtils.js +998 -1013
- package/dist/cjs/rendering/NiceCascadedShadows.js +381 -259
- package/dist/cjs/rendering/NiceRenderExport.js +424 -337
- package/dist/cjs/rendering/NiceSSAO.js +454 -337
- package/dist/cjs/rendering/NiceSSR.js +387 -261
- package/dist/cjs/rendering/NiceWebGPURenderer.js +359 -230
- package/dist/cjs/uv/NiceUVEditor.js +787 -550
- package/dist/cjs/uv/UVEditor.module.css.js +53 -5
- package/dist/cjs/uv/uvEditorTypes.js +59 -76
- package/dist/cjs/uv/uvEditorUtils.js +501 -575
- package/dist/esm/collaborative/collaborativeScene.js +163 -205
- package/dist/esm/core/editorAsk.js +53 -40
- package/dist/esm/core/i18n.js +15 -13
- package/dist/esm/core/threeCompat.js +18 -26
- package/dist/esm/dance/DanceBridge.js +151 -176
- package/dist/esm/dance/DanceScoreEngine.js +211 -220
- package/dist/esm/dance/PoseDetector.js +304 -274
- package/dist/esm/index.js +258 -36
- package/dist/esm/material/MaterialEditor.module.css.js +242 -3
- package/dist/esm/material/NiceMaterialEditor.js +1215 -756
- package/dist/esm/material/materialEditorTypes.js +45 -48
- package/dist/esm/material/materialEditorUtils.js +713 -746
- package/dist/esm/material/materialNodeDefinitions.js +1415 -1458
- package/dist/esm/model/ModelEditor.js +91 -39
- package/dist/esm/model/ModelEditor.module.css.js +257 -3
- package/dist/esm/model/ModelEditorLeftPanel.js +126 -45
- package/dist/esm/model/ModelEditorMenuBar.js +359 -30
- package/dist/esm/model/ModelEditorRightPanel.js +634 -114
- package/dist/esm/model/ModelEditorSubComponents.js +265 -94
- package/dist/esm/model/ModelEditorTimeline.js +232 -32
- package/dist/esm/model/ModelEditorToolbar.js +170 -12
- package/dist/esm/model/ModelEditorViewport.js +231 -37
- package/dist/esm/model/ModelViewer.js +389 -62
- package/dist/esm/model/ModelViewer.module.css.js +77 -3
- package/dist/esm/model/NiceArmatureEditor.js +462 -258
- package/dist/esm/model/NiceMorphTargetEditor.js +322 -211
- package/dist/esm/model/NiceOctree.js +361 -304
- package/dist/esm/model/NicePhysicsSimulation.js +517 -282
- package/dist/esm/model/NiceProceduralGeometry.js +667 -284
- package/dist/esm/model/NiceTerrainEditor.js +584 -369
- package/dist/esm/model/NiceWeightPainter.js +373 -245
- package/dist/esm/model/NiceXRPreview.js +374 -292
- package/dist/esm/model/cadModeUtils.js +95 -88
- package/dist/esm/model/editorShortcuts.js +172 -193
- package/dist/esm/model/modelEditorTypes.js +90 -100
- package/dist/esm/model/modelEditorUtils.js +1056 -1128
- package/dist/esm/model/simsModeUtils.js +1021 -1035
- package/dist/esm/model/useModelEditor.js +1946 -1920
- package/dist/esm/model/useModelViewer.js +619 -647
- package/dist/esm/nice2dev-ui-3d.css +1 -1
- package/dist/esm/particle/NiceParticleEditor.js +1188 -570
- package/dist/esm/particle/ParticleEditor.module.css.js +122 -3
- package/dist/esm/particle/particleEditorTypes.js +69 -69
- package/dist/esm/particle/particleEditorUtils.js +1027 -1012
- package/dist/esm/rendering/NiceCascadedShadows.js +370 -243
- package/dist/esm/rendering/NiceRenderExport.js +413 -321
- package/dist/esm/rendering/NiceSSAO.js +450 -328
- package/dist/esm/rendering/NiceSSR.js +383 -252
- package/dist/esm/rendering/NiceWebGPURenderer.js +326 -214
- package/dist/esm/uv/NiceUVEditor.js +788 -549
- package/dist/esm/uv/UVEditor.module.css.js +53 -3
- package/dist/esm/uv/uvEditorTypes.js +68 -75
- package/dist/esm/uv/uvEditorUtils.js +515 -557
- package/package.json +7 -12
|
@@ -1,227 +1,218 @@
|
|
|
1
|
-
import { useRef, useState, useCallback } from
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* DanceScoreEngine — Compares detected poses against reference choreography
|
|
5
|
-
*
|
|
6
|
-
* Calculates real-time dance accuracy by comparing camera-detected Pose3DFrames
|
|
7
|
-
* against a reference sequence (from choreography DSL or recorded poses).
|
|
8
|
-
*/
|
|
9
|
-
// ── Default config ──────────────────────────────────────────────
|
|
1
|
+
import { useRef, useState, useCallback } from "react";
|
|
10
2
|
const DEFAULT_CONFIG = {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
3
|
+
keypointWeights: {},
|
|
4
|
+
perfectThreshold: 0.05,
|
|
5
|
+
goodThreshold: 0.12,
|
|
6
|
+
okThreshold: 0.25,
|
|
7
|
+
timingWindowSec: 0.15,
|
|
8
|
+
minConfidence: 0.4
|
|
17
9
|
};
|
|
18
|
-
// ── DanceScoreEngine ────────────────────────────────────────────
|
|
19
10
|
class DanceScoreEngine {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
64
|
-
const keypointScores = this.compareKeypoints(detectedPerson, refPerson);
|
|
65
|
-
const totalWeight = keypointScores.reduce((s, k) => s + k.weight, 0);
|
|
66
|
-
const weightedScore = totalWeight > 0
|
|
67
|
-
? keypointScores.reduce((s, k) => s + k.weight * (1 - Math.min(k.distance / this.config.okThreshold, 1)), 0) / totalWeight
|
|
68
|
-
: 0;
|
|
69
|
-
const rating = this.rateScore(weightedScore);
|
|
70
|
-
if (rating !== 'miss') {
|
|
71
|
-
this.combo++;
|
|
72
|
-
this.maxCombo = Math.max(this.maxCombo, this.combo);
|
|
73
|
-
}
|
|
74
|
-
else {
|
|
75
|
-
this.combo = 0;
|
|
76
|
-
}
|
|
77
|
-
const frameScore = {
|
|
78
|
-
frameIndex: detected.frame_index,
|
|
79
|
-
timestamp: detected.timestamp_sec,
|
|
80
|
-
overallScore: Math.round(weightedScore * 100),
|
|
81
|
-
rating,
|
|
82
|
-
keypointScores,
|
|
83
|
-
matchedRefIndex: refIndex,
|
|
84
|
-
};
|
|
85
|
-
this.frameScores.push(frameScore);
|
|
86
|
-
this.lastMatchedRef = refIndex;
|
|
87
|
-
return frameScore;
|
|
88
|
-
}
|
|
89
|
-
/** Get the final session result */
|
|
90
|
-
getResult() {
|
|
91
|
-
const counts = { perfect: 0, good: 0, ok: 0, miss: 0 };
|
|
92
|
-
let totalScore = 0;
|
|
93
|
-
for (const fs of this.frameScores) {
|
|
94
|
-
counts[fs.rating]++;
|
|
95
|
-
totalScore += fs.overallScore;
|
|
96
|
-
}
|
|
97
|
-
const maxScore = this.frameScores.length * 100;
|
|
98
|
-
const percentage = maxScore > 0 ? (totalScore / maxScore) * 100 : 0;
|
|
99
|
-
return {
|
|
100
|
-
totalScore,
|
|
101
|
-
maxScore,
|
|
102
|
-
percentage: Math.round(percentage * 10) / 10,
|
|
103
|
-
grade: this.percentageToGrade(percentage),
|
|
104
|
-
perfectCount: counts.perfect,
|
|
105
|
-
goodCount: counts.good,
|
|
106
|
-
okCount: counts.ok,
|
|
107
|
-
missCount: counts.miss,
|
|
108
|
-
frameScores: this.frameScores,
|
|
109
|
-
combo: this.combo,
|
|
110
|
-
maxCombo: this.maxCombo,
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
// ── Private ─────────────────────────────────────────────────────
|
|
114
|
-
findClosestRefFrame(timestamp) {
|
|
115
|
-
let best = 0;
|
|
116
|
-
let bestDist = Infinity;
|
|
117
|
-
const start = Math.max(0, this.lastMatchedRef);
|
|
118
|
-
for (let i = start; i < this.reference.length; i++) {
|
|
119
|
-
const dist = Math.abs(this.reference[i].timestamp_sec - timestamp);
|
|
120
|
-
if (dist < bestDist) {
|
|
121
|
-
bestDist = dist;
|
|
122
|
-
best = i;
|
|
123
|
-
}
|
|
124
|
-
if (this.reference[i].timestamp_sec > timestamp + this.config.timingWindowSec) {
|
|
125
|
-
break;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
return best;
|
|
129
|
-
}
|
|
130
|
-
compareKeypoints(detected, reference) {
|
|
131
|
-
var _a, _b;
|
|
132
|
-
const scores = [];
|
|
133
|
-
const refMap = new Map(reference.keypoints.map((kp) => [kp.name, kp]));
|
|
134
|
-
for (const dkp of detected.keypoints) {
|
|
135
|
-
if (((_a = dkp.confidence) !== null && _a !== void 0 ? _a : 0) < this.config.minConfidence) {
|
|
136
|
-
continue;
|
|
137
|
-
}
|
|
138
|
-
const rkp = refMap.get(dkp.name);
|
|
139
|
-
if (!rkp) {
|
|
140
|
-
continue;
|
|
141
|
-
}
|
|
142
|
-
const distance = this.keypointDistance(dkp, rkp);
|
|
143
|
-
const weight = (_b = this.config.keypointWeights[dkp.name]) !== null && _b !== void 0 ? _b : 1;
|
|
144
|
-
const rating = this.rateDistance(distance);
|
|
145
|
-
scores.push({ name: dkp.name, distance, rating, weight });
|
|
146
|
-
}
|
|
147
|
-
return scores;
|
|
148
|
-
}
|
|
149
|
-
keypointDistance(a, b) {
|
|
150
|
-
const dx = a.x - b.x, dy = a.y - b.y, dz = a.z - b.z;
|
|
151
|
-
return Math.sqrt(dx * dx + dy * dy + dz * dz);
|
|
152
|
-
}
|
|
153
|
-
rateDistance(distance) {
|
|
154
|
-
if (distance <= this.config.perfectThreshold) {
|
|
155
|
-
return 'perfect';
|
|
156
|
-
}
|
|
157
|
-
if (distance <= this.config.goodThreshold) {
|
|
158
|
-
return 'good';
|
|
159
|
-
}
|
|
160
|
-
if (distance <= this.config.okThreshold) {
|
|
161
|
-
return 'ok';
|
|
162
|
-
}
|
|
163
|
-
return 'miss';
|
|
164
|
-
}
|
|
165
|
-
rateScore(normalizedScore) {
|
|
166
|
-
if (normalizedScore >= 0.9) {
|
|
167
|
-
return 'perfect';
|
|
168
|
-
}
|
|
169
|
-
if (normalizedScore >= 0.7) {
|
|
170
|
-
return 'good';
|
|
171
|
-
}
|
|
172
|
-
if (normalizedScore >= 0.4) {
|
|
173
|
-
return 'ok';
|
|
174
|
-
}
|
|
175
|
-
return 'miss';
|
|
176
|
-
}
|
|
177
|
-
recordMiss() {
|
|
178
|
-
this.combo = 0;
|
|
179
|
-
}
|
|
180
|
-
percentageToGrade(pct) {
|
|
181
|
-
if (pct >= 95) {
|
|
182
|
-
return 'S';
|
|
183
|
-
}
|
|
184
|
-
if (pct >= 85) {
|
|
185
|
-
return 'A';
|
|
186
|
-
}
|
|
187
|
-
if (pct >= 70) {
|
|
188
|
-
return 'B';
|
|
189
|
-
}
|
|
190
|
-
if (pct >= 55) {
|
|
191
|
-
return 'C';
|
|
192
|
-
}
|
|
193
|
-
if (pct >= 40) {
|
|
194
|
-
return 'D';
|
|
195
|
-
}
|
|
196
|
-
return 'F';
|
|
11
|
+
constructor(config = {}) {
|
|
12
|
+
this.reference = [];
|
|
13
|
+
this.frameScores = [];
|
|
14
|
+
this.lastMatchedRef = -1;
|
|
15
|
+
this.combo = 0;
|
|
16
|
+
this.maxCombo = 0;
|
|
17
|
+
this.config = { ...DEFAULT_CONFIG, ...config };
|
|
18
|
+
}
|
|
19
|
+
/** Load a reference choreography sequence */
|
|
20
|
+
loadReference(sequence) {
|
|
21
|
+
this.reference = sequence.frames;
|
|
22
|
+
this.reset();
|
|
23
|
+
}
|
|
24
|
+
/** Load reference from raw frames */
|
|
25
|
+
loadReferenceFrames(frames) {
|
|
26
|
+
this.reference = frames;
|
|
27
|
+
this.reset();
|
|
28
|
+
}
|
|
29
|
+
/** Reset scoring state for a new session */
|
|
30
|
+
reset() {
|
|
31
|
+
this.frameScores = [];
|
|
32
|
+
this.lastMatchedRef = -1;
|
|
33
|
+
this.combo = 0;
|
|
34
|
+
this.maxCombo = 0;
|
|
35
|
+
}
|
|
36
|
+
/** Score a single detected frame against the reference */
|
|
37
|
+
scoreFrame(detected) {
|
|
38
|
+
const refIndex = this.findClosestRefFrame(detected.timestamp_sec);
|
|
39
|
+
const refFrame = this.reference[refIndex];
|
|
40
|
+
const detectedPerson = detected.persons[0];
|
|
41
|
+
const refPerson = refFrame?.persons[0];
|
|
42
|
+
if (!detectedPerson || !refPerson) {
|
|
43
|
+
const missFrame = {
|
|
44
|
+
frameIndex: detected.frame_index,
|
|
45
|
+
timestamp: detected.timestamp_sec,
|
|
46
|
+
overallScore: 0,
|
|
47
|
+
rating: "miss",
|
|
48
|
+
keypointScores: [],
|
|
49
|
+
matchedRefIndex: refIndex
|
|
50
|
+
};
|
|
51
|
+
this.recordMiss();
|
|
52
|
+
this.frameScores.push(missFrame);
|
|
53
|
+
return missFrame;
|
|
197
54
|
}
|
|
55
|
+
const keypointScores = this.compareKeypoints(detectedPerson, refPerson);
|
|
56
|
+
const totalWeight = keypointScores.reduce((s, k) => s + k.weight, 0);
|
|
57
|
+
const weightedScore = totalWeight > 0 ? keypointScores.reduce(
|
|
58
|
+
(s, k) => s + k.weight * (1 - Math.min(k.distance / this.config.okThreshold, 1)),
|
|
59
|
+
0
|
|
60
|
+
) / totalWeight : 0;
|
|
61
|
+
const rating = this.rateScore(weightedScore);
|
|
62
|
+
if (rating !== "miss") {
|
|
63
|
+
this.combo++;
|
|
64
|
+
this.maxCombo = Math.max(this.maxCombo, this.combo);
|
|
65
|
+
} else {
|
|
66
|
+
this.combo = 0;
|
|
67
|
+
}
|
|
68
|
+
const frameScore = {
|
|
69
|
+
frameIndex: detected.frame_index,
|
|
70
|
+
timestamp: detected.timestamp_sec,
|
|
71
|
+
overallScore: Math.round(weightedScore * 100),
|
|
72
|
+
rating,
|
|
73
|
+
keypointScores,
|
|
74
|
+
matchedRefIndex: refIndex
|
|
75
|
+
};
|
|
76
|
+
this.frameScores.push(frameScore);
|
|
77
|
+
this.lastMatchedRef = refIndex;
|
|
78
|
+
return frameScore;
|
|
79
|
+
}
|
|
80
|
+
/** Get the final session result */
|
|
81
|
+
getResult() {
|
|
82
|
+
const counts = { perfect: 0, good: 0, ok: 0, miss: 0 };
|
|
83
|
+
let totalScore = 0;
|
|
84
|
+
for (const fs of this.frameScores) {
|
|
85
|
+
counts[fs.rating]++;
|
|
86
|
+
totalScore += fs.overallScore;
|
|
87
|
+
}
|
|
88
|
+
const maxScore = this.frameScores.length * 100;
|
|
89
|
+
const percentage = maxScore > 0 ? totalScore / maxScore * 100 : 0;
|
|
90
|
+
return {
|
|
91
|
+
totalScore,
|
|
92
|
+
maxScore,
|
|
93
|
+
percentage: Math.round(percentage * 10) / 10,
|
|
94
|
+
grade: this.percentageToGrade(percentage),
|
|
95
|
+
perfectCount: counts.perfect,
|
|
96
|
+
goodCount: counts.good,
|
|
97
|
+
okCount: counts.ok,
|
|
98
|
+
missCount: counts.miss,
|
|
99
|
+
frameScores: this.frameScores,
|
|
100
|
+
combo: this.combo,
|
|
101
|
+
maxCombo: this.maxCombo
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
// ── Private ─────────────────────────────────────────────────────
|
|
105
|
+
findClosestRefFrame(timestamp) {
|
|
106
|
+
let best = 0;
|
|
107
|
+
let bestDist = Infinity;
|
|
108
|
+
const start = Math.max(0, this.lastMatchedRef);
|
|
109
|
+
for (let i = start; i < this.reference.length; i++) {
|
|
110
|
+
const dist = Math.abs(this.reference[i].timestamp_sec - timestamp);
|
|
111
|
+
if (dist < bestDist) {
|
|
112
|
+
bestDist = dist;
|
|
113
|
+
best = i;
|
|
114
|
+
}
|
|
115
|
+
if (this.reference[i].timestamp_sec > timestamp + this.config.timingWindowSec) {
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return best;
|
|
120
|
+
}
|
|
121
|
+
compareKeypoints(detected, reference) {
|
|
122
|
+
const scores = [];
|
|
123
|
+
const refMap = new Map(reference.keypoints.map((kp) => [kp.name, kp]));
|
|
124
|
+
for (const dkp of detected.keypoints) {
|
|
125
|
+
if ((dkp.confidence ?? 0) < this.config.minConfidence) {
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
const rkp = refMap.get(dkp.name);
|
|
129
|
+
if (!rkp) {
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
const distance = this.keypointDistance(dkp, rkp);
|
|
133
|
+
const weight = this.config.keypointWeights[dkp.name] ?? 1;
|
|
134
|
+
const rating = this.rateDistance(distance);
|
|
135
|
+
scores.push({ name: dkp.name, distance, rating, weight });
|
|
136
|
+
}
|
|
137
|
+
return scores;
|
|
138
|
+
}
|
|
139
|
+
keypointDistance(a, b) {
|
|
140
|
+
const dx = a.x - b.x, dy = a.y - b.y, dz = a.z - b.z;
|
|
141
|
+
return Math.sqrt(dx * dx + dy * dy + dz * dz);
|
|
142
|
+
}
|
|
143
|
+
rateDistance(distance) {
|
|
144
|
+
if (distance <= this.config.perfectThreshold) {
|
|
145
|
+
return "perfect";
|
|
146
|
+
}
|
|
147
|
+
if (distance <= this.config.goodThreshold) {
|
|
148
|
+
return "good";
|
|
149
|
+
}
|
|
150
|
+
if (distance <= this.config.okThreshold) {
|
|
151
|
+
return "ok";
|
|
152
|
+
}
|
|
153
|
+
return "miss";
|
|
154
|
+
}
|
|
155
|
+
rateScore(normalizedScore) {
|
|
156
|
+
if (normalizedScore >= 0.9) {
|
|
157
|
+
return "perfect";
|
|
158
|
+
}
|
|
159
|
+
if (normalizedScore >= 0.7) {
|
|
160
|
+
return "good";
|
|
161
|
+
}
|
|
162
|
+
if (normalizedScore >= 0.4) {
|
|
163
|
+
return "ok";
|
|
164
|
+
}
|
|
165
|
+
return "miss";
|
|
166
|
+
}
|
|
167
|
+
recordMiss() {
|
|
168
|
+
this.combo = 0;
|
|
169
|
+
}
|
|
170
|
+
percentageToGrade(pct) {
|
|
171
|
+
if (pct >= 95) {
|
|
172
|
+
return "S";
|
|
173
|
+
}
|
|
174
|
+
if (pct >= 85) {
|
|
175
|
+
return "A";
|
|
176
|
+
}
|
|
177
|
+
if (pct >= 70) {
|
|
178
|
+
return "B";
|
|
179
|
+
}
|
|
180
|
+
if (pct >= 55) {
|
|
181
|
+
return "C";
|
|
182
|
+
}
|
|
183
|
+
if (pct >= 40) {
|
|
184
|
+
return "D";
|
|
185
|
+
}
|
|
186
|
+
return "F";
|
|
187
|
+
}
|
|
198
188
|
}
|
|
199
|
-
// ── React hook ──────────────────────────────────────────────────
|
|
200
189
|
function useDanceScore(config) {
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
190
|
+
const engineRef = useRef(new DanceScoreEngine(config));
|
|
191
|
+
const [lastScore, setLastScore] = useState(null);
|
|
192
|
+
const [result, setResult] = useState(null);
|
|
193
|
+
const loadReference = useCallback((seq) => {
|
|
194
|
+
engineRef.current.loadReference(seq);
|
|
195
|
+
setLastScore(null);
|
|
196
|
+
setResult(null);
|
|
197
|
+
}, []);
|
|
198
|
+
const scoreFrame = useCallback((frame) => {
|
|
199
|
+
const score = engineRef.current.scoreFrame(frame);
|
|
200
|
+
setLastScore(score);
|
|
201
|
+
return score;
|
|
202
|
+
}, []);
|
|
203
|
+
const finish = useCallback(() => {
|
|
204
|
+
const r = engineRef.current.getResult();
|
|
205
|
+
setResult(r);
|
|
206
|
+
return r;
|
|
207
|
+
}, []);
|
|
208
|
+
const reset = useCallback(() => {
|
|
209
|
+
engineRef.current.reset();
|
|
210
|
+
setLastScore(null);
|
|
211
|
+
setResult(null);
|
|
212
|
+
}, []);
|
|
213
|
+
return { loadReference, scoreFrame, finish, reset, lastScore, result };
|
|
225
214
|
}
|
|
226
|
-
|
|
227
|
-
|
|
215
|
+
export {
|
|
216
|
+
DanceScoreEngine,
|
|
217
|
+
useDanceScore
|
|
218
|
+
};
|