@kubohiroya/turbowarp-aframe 0.4.0 → 0.5.0
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.ja.md +4 -2
- package/README.md +26 -2
- package/dist/extension-manifest.json +28 -0
- package/dist/turbowarp-aframe.js +74 -1
- package/docs/architecture.ja.md +1 -1
- package/docs/architecture.md +1 -1
- package/package.json +1 -1
- package/src/block-definitions.json +20 -0
- package/src/extension.ts +22 -1
- package/src/runtime-capability.ts +11 -0
- package/src/vrm.ts +25 -0
package/README.ja.md
CHANGED
|
@@ -45,10 +45,12 @@ interface AFrameRuntimeCapabilityV2 {
|
|
|
45
45
|
setVrmBoneRotation(selector: string, bone: string, x: number, y: number, z: number): void;
|
|
46
46
|
vrmBoneNames(selector: string): string[];
|
|
47
47
|
vrmStatus(selector: string): {state: 'none' | 'loading' | 'ready' | 'error'; error: string};
|
|
48
|
+
setVrmExpression(selector: string, name: string, weight: number): void;
|
|
49
|
+
vrmExpressionNames(selector: string): string[];
|
|
48
50
|
}
|
|
49
51
|
```
|
|
50
52
|
|
|
51
|
-
version 2は、scene操作に加えてVRMアバターを扱います。`loadVrm`は、A-Frameが読み込んだThree.jsの上でthree-vrmを動かし、selectorに最初に一致したnodeへモデルを読み込んで、準備ができると解決します。`setVrmBoneRotation`は、`leftUpperArm`などの正規化されたヒューマノイドのボーンへ、Tポーズからの回転を度のEuler角で設定します。どのVRMでも同じ回転が同じ意味になり、sceneのtickがモデル本来のボーンへ反映します。VRMの準備ができていないnode
|
|
53
|
+
version 2は、scene操作に加えてVRMアバターを扱います。`loadVrm`は、A-Frameが読み込んだThree.jsの上でthree-vrmを動かし、selectorに最初に一致したnodeへモデルを読み込んで、準備ができると解決します。`setVrmBoneRotation`は、`leftUpperArm`などの正規化されたヒューマノイドのボーンへ、Tポーズからの回転を度のEuler角で設定します。どのVRMでも同じ回転が同じ意味になり、sceneのtickがモデル本来のボーンへ反映します。VRMの準備ができていないnodeは飛ばし、存在しないボーン名は例外になります。`setVrmExpression`は、`happy`、`blink`、`aa`などのプリセットまたはカスタムの表情の重みを、three-vrmと同じく0〜1に丸めて設定し、sceneのtickが反映します。`vrmExpressionNames`はモデルが持つ表情名を返し、存在しない名前は例外になります。
|
|
52
54
|
|
|
53
55
|
このcapabilityが公開するのは宣言的template、selector、ヒューマノイドのボーン名だけです。private DOM node、A-Frame object、Three.js object、glTF内部実装は公開しません。未対応versionはfail closedし、機能拡張のdispose後に保持されたcapabilityを呼び出した場合も、すべて明示的に拒否します。
|
|
54
56
|
|
|
@@ -70,7 +72,7 @@ TurboWarp では `dist/turbowarp-aframe.js` を unsandboxed custom extension と
|
|
|
70
72
|
package として参照する場合は version を固定します。
|
|
71
73
|
|
|
72
74
|
```bash
|
|
73
|
-
pnpm add --save-exact @kubohiroya/turbowarp-aframe@0.
|
|
75
|
+
pnpm add --save-exact @kubohiroya/turbowarp-aframe@0.5.0
|
|
74
76
|
```
|
|
75
77
|
|
|
76
78
|
## ブロック概要
|
package/README.md
CHANGED
|
@@ -45,10 +45,12 @@ interface AFrameRuntimeCapabilityV2 {
|
|
|
45
45
|
setVrmBoneRotation(selector: string, bone: string, x: number, y: number, z: number): void;
|
|
46
46
|
vrmBoneNames(selector: string): string[];
|
|
47
47
|
vrmStatus(selector: string): {state: 'none' | 'loading' | 'ready' | 'error'; error: string};
|
|
48
|
+
setVrmExpression(selector: string, name: string, weight: number): void;
|
|
49
|
+
vrmExpressionNames(selector: string): string[];
|
|
48
50
|
}
|
|
49
51
|
```
|
|
50
52
|
|
|
51
|
-
Besides the scene operations, version 2 carries VRM avatars. `loadVrm` loads the model onto the first node matching the selector with three-vrm, running on the Three.js that A-Frame loaded, and resolves when it is ready. `setVrmBoneRotation` sets Euler degrees on a normalized humanoid bone such as `leftUpperArm`, relative to the T-pose, so the same rotation means the same thing on every VRM; the scene tick applies it to the model's own bones. Nodes whose VRM is not ready are skipped, and an unknown bone name throws.
|
|
53
|
+
Besides the scene operations, version 2 carries VRM avatars. `loadVrm` loads the model onto the first node matching the selector with three-vrm, running on the Three.js that A-Frame loaded, and resolves when it is ready. `setVrmBoneRotation` sets Euler degrees on a normalized humanoid bone such as `leftUpperArm`, relative to the T-pose, so the same rotation means the same thing on every VRM; the scene tick applies it to the model's own bones. Nodes whose VRM is not ready are skipped, and an unknown bone name throws. `setVrmExpression` sets the weight of a preset expression such as `happy`, `blink`, or `aa`, or of a custom one, clamped to 0 through 1 as three-vrm does, and the scene tick applies it; `vrmExpressionNames` lists the names the model has, and an unknown name throws.
|
|
52
54
|
|
|
53
55
|
The capability deliberately exposes declarative templates, selectors, and humanoid bone names, not private DOM nodes, A-Frame objects, Three.js objects, or glTF internals. Unsupported versions fail closed. A retained capability reference also rejects every operation after the extension is disposed.
|
|
54
56
|
|
|
@@ -70,7 +72,7 @@ Load `dist/turbowarp-aframe.js` as an unsandboxed custom extension in TurboWarp.
|
|
|
70
72
|
For package-based reuse, pin the version:
|
|
71
73
|
|
|
72
74
|
```bash
|
|
73
|
-
pnpm add --save-exact @kubohiroya/turbowarp-aframe@0.
|
|
75
|
+
pnpm add --save-exact @kubohiroya/turbowarp-aframe@0.5.0
|
|
74
76
|
```
|
|
75
77
|
|
|
76
78
|
## Block reference
|
|
@@ -465,6 +467,28 @@ Returns the humanoid bone names of the first matching node's VRM as a JSON array
|
|
|
465
467
|
| Opcode | `vrmBoneNames` |
|
|
466
468
|
| `SELECTOR` | String, default: `#avatar` |
|
|
467
469
|
|
|
470
|
+
### `set VRM [SELECTOR] expression [NAME] to [WEIGHT]`
|
|
471
|
+
|
|
472
|
+
Sets the weight, clamped to 0 through 1, of a preset or custom VRM expression such as happy or blink on every matching node whose VRM is ready.
|
|
473
|
+
|
|
474
|
+
| Property | Value |
|
|
475
|
+
|---|---|
|
|
476
|
+
| Type | Command |
|
|
477
|
+
| Opcode | `setVrmExpression` |
|
|
478
|
+
| `SELECTOR` | String, default: `#avatar` |
|
|
479
|
+
| `NAME` | String, default: `happy` |
|
|
480
|
+
| `WEIGHT` | Number, default: `1` |
|
|
481
|
+
|
|
482
|
+
### `VRM [SELECTOR] expressions`
|
|
483
|
+
|
|
484
|
+
Returns the preset and custom expression names of the first matching node's VRM as a JSON array.
|
|
485
|
+
|
|
486
|
+
| Property | Value |
|
|
487
|
+
|---|---|
|
|
488
|
+
| Type | Reporter |
|
|
489
|
+
| Opcode | `vrmExpressionNames` |
|
|
490
|
+
| `SELECTOR` | String, default: `#avatar` |
|
|
491
|
+
|
|
468
492
|
### `VRM [SELECTOR] state`
|
|
469
493
|
|
|
470
494
|
Returns none, loading, ready, or error with its reason for the first matching node.
|
|
@@ -519,6 +519,24 @@
|
|
|
519
519
|
}
|
|
520
520
|
]
|
|
521
521
|
},
|
|
522
|
+
{
|
|
523
|
+
"opcode": "setVrmExpression",
|
|
524
|
+
"blockType": "COMMAND",
|
|
525
|
+
"arguments": [
|
|
526
|
+
{
|
|
527
|
+
"id": "NAME",
|
|
528
|
+
"type": "STRING"
|
|
529
|
+
},
|
|
530
|
+
{
|
|
531
|
+
"id": "SELECTOR",
|
|
532
|
+
"type": "STRING"
|
|
533
|
+
},
|
|
534
|
+
{
|
|
535
|
+
"id": "WEIGHT",
|
|
536
|
+
"type": "NUMBER"
|
|
537
|
+
}
|
|
538
|
+
]
|
|
539
|
+
},
|
|
522
540
|
{
|
|
523
541
|
"opcode": "stopAnimationClip",
|
|
524
542
|
"blockType": "COMMAND",
|
|
@@ -543,6 +561,16 @@
|
|
|
543
561
|
}
|
|
544
562
|
]
|
|
545
563
|
},
|
|
564
|
+
{
|
|
565
|
+
"opcode": "vrmExpressionNames",
|
|
566
|
+
"blockType": "REPORTER",
|
|
567
|
+
"arguments": [
|
|
568
|
+
{
|
|
569
|
+
"id": "SELECTOR",
|
|
570
|
+
"type": "STRING"
|
|
571
|
+
}
|
|
572
|
+
]
|
|
573
|
+
},
|
|
546
574
|
{
|
|
547
575
|
"opcode": "vrmState",
|
|
548
576
|
"blockType": "REPORTER",
|
package/dist/turbowarp-aframe.js
CHANGED
|
@@ -640,6 +640,36 @@
|
|
|
640
640
|
"defaultValue": "#avatar"
|
|
641
641
|
} }
|
|
642
642
|
},
|
|
643
|
+
{
|
|
644
|
+
"opcode": "setVrmExpression",
|
|
645
|
+
"blockType": "COMMAND",
|
|
646
|
+
"text": "set VRM [SELECTOR] expression [NAME] to [WEIGHT]",
|
|
647
|
+
"description": "Sets the weight, clamped to 0 through 1, of a preset or custom VRM expression such as happy or blink on every matching node whose VRM is ready.",
|
|
648
|
+
"arguments": {
|
|
649
|
+
"SELECTOR": {
|
|
650
|
+
"type": "STRING",
|
|
651
|
+
"defaultValue": "#avatar"
|
|
652
|
+
},
|
|
653
|
+
"NAME": {
|
|
654
|
+
"type": "STRING",
|
|
655
|
+
"defaultValue": "happy"
|
|
656
|
+
},
|
|
657
|
+
"WEIGHT": {
|
|
658
|
+
"type": "NUMBER",
|
|
659
|
+
"defaultValue": 1
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
},
|
|
663
|
+
{
|
|
664
|
+
"opcode": "vrmExpressionNames",
|
|
665
|
+
"blockType": "REPORTER",
|
|
666
|
+
"text": "VRM [SELECTOR] expressions",
|
|
667
|
+
"description": "Returns the preset and custom expression names of the first matching node's VRM as a JSON array.",
|
|
668
|
+
"arguments": { "SELECTOR": {
|
|
669
|
+
"type": "STRING",
|
|
670
|
+
"defaultValue": "#avatar"
|
|
671
|
+
} }
|
|
672
|
+
},
|
|
643
673
|
{
|
|
644
674
|
"opcode": "vrmState",
|
|
645
675
|
"blockType": "REPORTER",
|
|
@@ -700,6 +730,14 @@
|
|
|
700
730
|
vrmStatus(selector) {
|
|
701
731
|
assertActive();
|
|
702
732
|
return scene.vrmStatus(selector);
|
|
733
|
+
},
|
|
734
|
+
setVrmExpression(selector, name, weight) {
|
|
735
|
+
assertActive();
|
|
736
|
+
scene.setVrmExpression(selector, name, weight);
|
|
737
|
+
},
|
|
738
|
+
vrmExpressionNames(selector) {
|
|
739
|
+
assertActive();
|
|
740
|
+
return scene.vrmExpressionNames(selector);
|
|
703
741
|
}
|
|
704
742
|
};
|
|
705
743
|
const capability = Object.freeze({
|
|
@@ -6875,6 +6913,20 @@
|
|
|
6875
6913
|
const { degToRad } = this.requireThree().MathUtils;
|
|
6876
6914
|
node.rotation.set(degToRad(degrees.x), degToRad(degrees.y), degToRad(degrees.z));
|
|
6877
6915
|
}
|
|
6916
|
+
/**
|
|
6917
|
+
* Sets an expression's weight. The weight is clamped to 0 through 1, as three-vrm does, and
|
|
6918
|
+
* the scene tick applies it with the other expressions.
|
|
6919
|
+
*/
|
|
6920
|
+
setExpression(nodeId, name, weight) {
|
|
6921
|
+
if (!Number.isFinite(weight)) throw new Error(`VRM expression weight must be a number: ${weight}`);
|
|
6922
|
+
const expressions = this.requireVrm(nodeId).expressionManager;
|
|
6923
|
+
if (expressions === void 0) throw new Error(`VRM ${nodeId} has no expressions.`);
|
|
6924
|
+
if (expressions.getExpression(name) == null) throw new Error(`VRM ${nodeId} has no expression: ${name}`);
|
|
6925
|
+
expressions.setValue(name, Math.min(Math.max(weight, 0), 1));
|
|
6926
|
+
}
|
|
6927
|
+
expressionNames(nodeId) {
|
|
6928
|
+
return (this.entries.get(nodeId)?.vrm?.expressionManager?.expressions ?? []).map((expression) => expression.expressionName);
|
|
6929
|
+
}
|
|
6878
6930
|
boneNames(nodeId) {
|
|
6879
6931
|
const vrm = this.entries.get(nodeId)?.vrm;
|
|
6880
6932
|
if (vrm === null || vrm === void 0) return [];
|
|
@@ -6995,7 +7047,13 @@
|
|
|
6995
7047
|
Z: z
|
|
6996
7048
|
}),
|
|
6997
7049
|
vrmBoneNames: (selector) => this.vrmBoneNamesFor(Scratch.Cast.toString(selector)),
|
|
6998
|
-
vrmStatus: (selector) => this.vrmStatusFor(Scratch.Cast.toString(selector))
|
|
7050
|
+
vrmStatus: (selector) => this.vrmStatusFor(Scratch.Cast.toString(selector)),
|
|
7051
|
+
setVrmExpression: (selector, name, weight) => this.setVrmExpression({
|
|
7052
|
+
SELECTOR: selector,
|
|
7053
|
+
NAME: name,
|
|
7054
|
+
WEIGHT: weight
|
|
7055
|
+
}),
|
|
7056
|
+
vrmExpressionNames: (selector) => this.vrmExpressionNamesFor(Scratch.Cast.toString(selector))
|
|
6999
7057
|
}, () => this.assertActive());
|
|
7000
7058
|
const runtime = Scratch.vm?.runtime;
|
|
7001
7059
|
if (runtime) runtime[runtimeCapabilityKey] = this.runtimeCapability;
|
|
@@ -7270,6 +7328,17 @@
|
|
|
7270
7328
|
this.vrms.setBoneRotation(node.id, bone, rotation);
|
|
7271
7329
|
}
|
|
7272
7330
|
}
|
|
7331
|
+
setVrmExpression(args) {
|
|
7332
|
+
const name = Scratch.Cast.toString(args.NAME).trim();
|
|
7333
|
+
const weight = Scratch.Cast.toNumber(args.WEIGHT);
|
|
7334
|
+
for (const node of this.matches(Scratch.Cast.toString(args.SELECTOR))) {
|
|
7335
|
+
if (this.vrms.state(node.id) !== "ready") continue;
|
|
7336
|
+
this.vrms.setExpression(node.id, name, weight);
|
|
7337
|
+
}
|
|
7338
|
+
}
|
|
7339
|
+
vrmExpressionNames(args) {
|
|
7340
|
+
return JSON.stringify(this.vrmExpressionNamesFor(Scratch.Cast.toString(args.SELECTOR)));
|
|
7341
|
+
}
|
|
7273
7342
|
vrmBoneNames(args) {
|
|
7274
7343
|
return JSON.stringify(this.vrmBoneNamesFor(Scratch.Cast.toString(args.SELECTOR)));
|
|
7275
7344
|
}
|
|
@@ -7662,6 +7731,10 @@
|
|
|
7662
7731
|
const node = this.firstMatch(selector);
|
|
7663
7732
|
return node === void 0 ? [] : this.vrms.boneNames(node.id);
|
|
7664
7733
|
}
|
|
7734
|
+
vrmExpressionNamesFor(selector) {
|
|
7735
|
+
const node = this.firstMatch(selector);
|
|
7736
|
+
return node === void 0 ? [] : this.vrms.expressionNames(node.id);
|
|
7737
|
+
}
|
|
7665
7738
|
vrmStatusFor(selector) {
|
|
7666
7739
|
const node = this.firstMatch(selector);
|
|
7667
7740
|
if (node === void 0) return {
|
package/docs/architecture.ja.md
CHANGED
|
@@ -24,7 +24,7 @@ src/config.ts + src/block-definitions.json
|
|
|
24
24
|
|
|
25
25
|
## version付きruntime capability
|
|
26
26
|
|
|
27
|
-
機能拡張は`Scratch.vm.runtime.turbowarpAFrameCapability`を公開します。version 2は、`loadTemplate`、`createFromTemplate`、`setPosition`、`setRotation`、`emitEvent`、`deleteSelector`、`countSelector`に、`loadVrm`、`setVrmBoneRotation`、`vrmBoneNames`、`vrmStatus`を加えた、freezeされた狭い型付きportです。scene操作だけを持っていたversion 1は、version 2と並べて残さず0.4.0で撤去しました。正しく保つ契約を1
|
|
27
|
+
機能拡張は`Scratch.vm.runtime.turbowarpAFrameCapability`を公開します。version 2は、`loadTemplate`、`createFromTemplate`、`setPosition`、`setRotation`、`emitEvent`、`deleteSelector`、`countSelector`に、`loadVrm`、`setVrmBoneRotation`、`vrmBoneNames`、`vrmStatus`、`setVrmExpression`、`vrmExpressionNames`を加えた、freezeされた狭い型付きportです。scene操作だけを持っていたversion 1は、version 2と並べて残さず0.4.0で撤去しました。正しく保つ契約を1つにするためです。表情の操作は、methodを加えるだけでconsumerは使うmethodの有無を確かめるため、versionを変えずにversion 2へ加えました。
|
|
28
28
|
|
|
29
29
|
各port methodは対応するblock handlerへ委譲します。そのため、block呼び出しと複合機能拡張からの呼び出しは、cast、validation、selector matching、event queue、機能拡張所有のscene stateを共有します。portはDOM element、A-Frame/Three.js object、glTF内部実装を公開しません。
|
|
30
30
|
|
package/docs/architecture.md
CHANGED
|
@@ -24,7 +24,7 @@ The generated JavaScript bundle is an unsandboxed TurboWarp extension. The manif
|
|
|
24
24
|
|
|
25
25
|
## Versioned Runtime Capability
|
|
26
26
|
|
|
27
|
-
The extension publishes `Scratch.vm.runtime.turbowarpAFrameCapability`. Version 2 is a narrow typed, frozen port containing `loadTemplate`, `createFromTemplate`, `setPosition`, `setRotation`, `emitEvent`, `deleteSelector`, and `countSelector`, plus `loadVrm`, `setVrmBoneRotation`, `vrmBoneNames`, and `
|
|
27
|
+
The extension publishes `Scratch.vm.runtime.turbowarpAFrameCapability`. Version 2 is a narrow typed, frozen port containing `loadTemplate`, `createFromTemplate`, `setPosition`, `setRotation`, `emitEvent`, `deleteSelector`, and `countSelector`, plus `loadVrm`, `setVrmBoneRotation`, `vrmBoneNames`, `vrmStatus`, `setVrmExpression`, and `vrmExpressionNames`. The expression operations were added to version 2 without changing its version, because they only add methods and a consumer checks for the methods it uses. Version 1, which had only the scene operations, was removed in 0.4.0 rather than kept beside version 2, so there is a single contract to keep correct.
|
|
28
28
|
|
|
29
29
|
Each port method delegates to the corresponding block handler. Consequently, block calls and composite-extension calls share casting, validation, selector matching, event queuing, and the extension-owned scene state. The port never exposes DOM elements, A-Frame/Three.js objects, or glTF internals.
|
|
30
30
|
|
package/package.json
CHANGED
|
@@ -357,6 +357,26 @@
|
|
|
357
357
|
"SELECTOR": {"type": "STRING", "defaultValue": "#avatar"}
|
|
358
358
|
}
|
|
359
359
|
},
|
|
360
|
+
{
|
|
361
|
+
"opcode": "setVrmExpression",
|
|
362
|
+
"blockType": "COMMAND",
|
|
363
|
+
"text": "set VRM [SELECTOR] expression [NAME] to [WEIGHT]",
|
|
364
|
+
"description": "Sets the weight, clamped to 0 through 1, of a preset or custom VRM expression such as happy or blink on every matching node whose VRM is ready.",
|
|
365
|
+
"arguments": {
|
|
366
|
+
"SELECTOR": {"type": "STRING", "defaultValue": "#avatar"},
|
|
367
|
+
"NAME": {"type": "STRING", "defaultValue": "happy"},
|
|
368
|
+
"WEIGHT": {"type": "NUMBER", "defaultValue": 1}
|
|
369
|
+
}
|
|
370
|
+
},
|
|
371
|
+
{
|
|
372
|
+
"opcode": "vrmExpressionNames",
|
|
373
|
+
"blockType": "REPORTER",
|
|
374
|
+
"text": "VRM [SELECTOR] expressions",
|
|
375
|
+
"description": "Returns the preset and custom expression names of the first matching node's VRM as a JSON array.",
|
|
376
|
+
"arguments": {
|
|
377
|
+
"SELECTOR": {"type": "STRING", "defaultValue": "#avatar"}
|
|
378
|
+
}
|
|
379
|
+
},
|
|
360
380
|
{
|
|
361
381
|
"opcode": "vrmState",
|
|
362
382
|
"blockType": "REPORTER",
|
package/src/extension.ts
CHANGED
|
@@ -166,7 +166,10 @@ export class TurboWarpAFrameExtension implements TurboWarpExtension {
|
|
|
166
166
|
setVrmBoneRotation: (selector, bone, x, y, z) =>
|
|
167
167
|
this.setVrmBoneRotation({SELECTOR: selector, BONE: bone, X: x, Y: y, Z: z}),
|
|
168
168
|
vrmBoneNames: (selector) => this.vrmBoneNamesFor(Scratch.Cast.toString(selector)),
|
|
169
|
-
vrmStatus: (selector) => this.vrmStatusFor(Scratch.Cast.toString(selector))
|
|
169
|
+
vrmStatus: (selector) => this.vrmStatusFor(Scratch.Cast.toString(selector)),
|
|
170
|
+
setVrmExpression: (selector, name, weight) =>
|
|
171
|
+
this.setVrmExpression({SELECTOR: selector, NAME: name, WEIGHT: weight}),
|
|
172
|
+
vrmExpressionNames: (selector) => this.vrmExpressionNamesFor(Scratch.Cast.toString(selector))
|
|
170
173
|
},
|
|
171
174
|
() => this.assertActive()
|
|
172
175
|
);
|
|
@@ -546,6 +549,19 @@ export class TurboWarpAFrameExtension implements TurboWarpExtension {
|
|
|
546
549
|
}
|
|
547
550
|
}
|
|
548
551
|
|
|
552
|
+
public setVrmExpression(args: {SELECTOR: unknown; NAME: unknown; WEIGHT: unknown}): void {
|
|
553
|
+
const name = Scratch.Cast.toString(args.NAME).trim();
|
|
554
|
+
const weight = Scratch.Cast.toNumber(args.WEIGHT);
|
|
555
|
+
for (const node of this.matches(Scratch.Cast.toString(args.SELECTOR))) {
|
|
556
|
+
if (this.vrms.state(node.id) !== 'ready') continue;
|
|
557
|
+
this.vrms.setExpression(node.id, name, weight);
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
public vrmExpressionNames(args: {SELECTOR: unknown}): string {
|
|
562
|
+
return JSON.stringify(this.vrmExpressionNamesFor(Scratch.Cast.toString(args.SELECTOR)));
|
|
563
|
+
}
|
|
564
|
+
|
|
549
565
|
public vrmBoneNames(args: {SELECTOR: unknown}): string {
|
|
550
566
|
return JSON.stringify(this.vrmBoneNamesFor(Scratch.Cast.toString(args.SELECTOR)));
|
|
551
567
|
}
|
|
@@ -1097,6 +1113,11 @@ export class TurboWarpAFrameExtension implements TurboWarpExtension {
|
|
|
1097
1113
|
return node === undefined ? [] : this.vrms.boneNames(node.id);
|
|
1098
1114
|
}
|
|
1099
1115
|
|
|
1116
|
+
private vrmExpressionNamesFor(selector: string): string[] {
|
|
1117
|
+
const node = this.firstMatch(selector);
|
|
1118
|
+
return node === undefined ? [] : this.vrms.expressionNames(node.id);
|
|
1119
|
+
}
|
|
1120
|
+
|
|
1100
1121
|
private vrmStatusFor(selector: string): AFrameVrmStatus {
|
|
1101
1122
|
const node = this.firstMatch(selector);
|
|
1102
1123
|
if (node === undefined) return {state: 'none', error: ''};
|
|
@@ -26,6 +26,9 @@ export interface AFrameVrmPort {
|
|
|
26
26
|
setVrmBoneRotation(selector: string, bone: string, x: number, y: number, z: number): void;
|
|
27
27
|
vrmBoneNames(selector: string): string[];
|
|
28
28
|
vrmStatus(selector: string): AFrameVrmStatus;
|
|
29
|
+
/** Weight from 0 through 1, clamped, of a preset or custom VRM expression. */
|
|
30
|
+
setVrmExpression(selector: string, name: string, weight: number): void;
|
|
31
|
+
vrmExpressionNames(selector: string): string[];
|
|
29
32
|
}
|
|
30
33
|
|
|
31
34
|
export interface AFrameRuntimeCapabilityV2 extends AFrameScenePort, AFrameVrmPort {
|
|
@@ -84,6 +87,14 @@ export function createRuntimeCapability(
|
|
|
84
87
|
vrmStatus(selector) {
|
|
85
88
|
assertActive();
|
|
86
89
|
return scene.vrmStatus(selector);
|
|
90
|
+
},
|
|
91
|
+
setVrmExpression(selector, name, weight) {
|
|
92
|
+
assertActive();
|
|
93
|
+
scene.setVrmExpression(selector, name, weight);
|
|
94
|
+
},
|
|
95
|
+
vrmExpressionNames(selector) {
|
|
96
|
+
assertActive();
|
|
97
|
+
return scene.vrmExpressionNames(selector);
|
|
87
98
|
}
|
|
88
99
|
};
|
|
89
100
|
|
package/src/vrm.ts
CHANGED
|
@@ -22,6 +22,11 @@ export interface VrmLike {
|
|
|
22
22
|
humanBones: Record<string, unknown>;
|
|
23
23
|
getNormalizedBoneNode(name: string): BoneLike | null;
|
|
24
24
|
};
|
|
25
|
+
expressionManager?: {
|
|
26
|
+
expressions: ReadonlyArray<{expressionName: string}>;
|
|
27
|
+
getExpression(name: string): unknown;
|
|
28
|
+
setValue(name: string, weight: number): void;
|
|
29
|
+
};
|
|
25
30
|
update(deltaSeconds: number): void;
|
|
26
31
|
}
|
|
27
32
|
|
|
@@ -86,6 +91,26 @@ export class VrmAvatars {
|
|
|
86
91
|
node.rotation.set(degToRad(degrees.x), degToRad(degrees.y), degToRad(degrees.z));
|
|
87
92
|
}
|
|
88
93
|
|
|
94
|
+
/**
|
|
95
|
+
* Sets an expression's weight. The weight is clamped to 0 through 1, as three-vrm does, and
|
|
96
|
+
* the scene tick applies it with the other expressions.
|
|
97
|
+
*/
|
|
98
|
+
public setExpression(nodeId: string, name: string, weight: number): void {
|
|
99
|
+
if (!Number.isFinite(weight)) throw new Error(`VRM expression weight must be a number: ${weight}`);
|
|
100
|
+
const vrm = this.requireVrm(nodeId);
|
|
101
|
+
const expressions = vrm.expressionManager;
|
|
102
|
+
if (expressions === undefined) throw new Error(`VRM ${nodeId} has no expressions.`);
|
|
103
|
+
if (expressions.getExpression(name) == null) {
|
|
104
|
+
throw new Error(`VRM ${nodeId} has no expression: ${name}`);
|
|
105
|
+
}
|
|
106
|
+
expressions.setValue(name, Math.min(Math.max(weight, 0), 1));
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
public expressionNames(nodeId: string): string[] {
|
|
110
|
+
const expressions = this.entries.get(nodeId)?.vrm?.expressionManager?.expressions ?? [];
|
|
111
|
+
return expressions.map((expression) => expression.expressionName);
|
|
112
|
+
}
|
|
113
|
+
|
|
89
114
|
public boneNames(nodeId: string): string[] {
|
|
90
115
|
const vrm = this.entries.get(nodeId)?.vrm;
|
|
91
116
|
if (vrm === null || vrm === undefined) return [];
|