@kubohiroya/turbowarp-aframe 0.3.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 CHANGED
@@ -22,18 +22,18 @@ Scratch のスプライトや背景を 3D オブジェクトとして扱うの
22
22
  - Node.js 22 以上
23
23
  - Corepack 経由の pnpm
24
24
  - TurboWarp の unsandboxed extension support
25
- - ブラウザ利用時は、生成済み拡張を使うページまたはプロジェクト環境で A-Frame を読み込むこと
25
+ - jsDelivrへ接続できること。`create 3D scene`はそこからA-Frame 1.8.0を、versionとsubresource integrityで固定して読み込みます。自前のコピーを配信するオフライン会場のように、ページにA-Frame 1.8.0がすでにあれば何も読み込まず、ほかのversionがあれば拒否します
26
26
 
27
27
  unsandboxed 拡張はページ DOM を操作できます。信頼できる生成済み bundle だけを読み込んでください。
28
28
 
29
29
  ## runtime scene capability
30
30
 
31
- 複合的なunsandboxed機能拡張は、version付きruntime capabilityを通じてブロックと同じscene操作を利用できます。`Scratch.vm.runtime.turbowarpAFrameCapability`を取得し、最初に`requireVersion(1)`を呼んでから、次の同期メソッドを利用します。
31
+ 複合的なunsandboxed機能拡張は、version付きruntime capabilityを通じてブロックと同じscene操作を利用できます。`Scratch.vm.runtime.turbowarpAFrameCapability`を取得し、`requireVersion(2)`を呼んで、返ったオブジェクトを利用します。versionは2だけです。version 1は0.4.0で撤去し、それ以外のversionを要求すると例外になります。
32
32
 
33
33
  ```ts
34
- interface AFrameRuntimeCapabilityV1 {
35
- readonly version: 1;
36
- requireVersion(version: number): AFrameRuntimeCapabilityV1;
34
+ interface AFrameRuntimeCapabilityV2 {
35
+ readonly version: 2;
36
+ requireVersion(version: number): AFrameRuntimeCapabilityV2;
37
37
  loadTemplate(id: string, source: string): void;
38
38
  createFromTemplate(template: string, instance: string, parent: string): void;
39
39
  setPosition(selector: string, x: number, y: number, z: number): void;
@@ -41,10 +41,18 @@ interface AFrameRuntimeCapabilityV1 {
41
41
  emitEvent(type: string, selector: string, data: string): void;
42
42
  deleteSelector(selector: string): void;
43
43
  countSelector(selector: string): number;
44
+ loadVrm(url: string, selector: string): Promise<void>;
45
+ setVrmBoneRotation(selector: string, bone: string, x: number, y: number, z: number): void;
46
+ vrmBoneNames(selector: string): string[];
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[];
44
50
  }
45
51
  ```
46
52
 
47
- このcapabilityが公開するのは宣言的templateとselectorだけです。private DOM node、A-Frame object、Three.js object、glTF内部実装は公開しません。未対応versionはfail closedし、機能拡張のdispose後に保持されたcapabilityを呼び出した場合も、すべて明示的に拒否します。
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`はモデルが持つ表情名を返し、存在しない名前は例外になります。
54
+
55
+ このcapabilityが公開するのは宣言的template、selector、ヒューマノイドのボーン名だけです。private DOM node、A-Frame object、Three.js object、glTF内部実装は公開しません。未対応versionはfail closedし、機能拡張のdispose後に保持されたcapabilityを呼び出した場合も、すべて明示的に拒否します。
48
56
 
49
57
  ## インストール
50
58
 
@@ -64,7 +72,7 @@ TurboWarp では `dist/turbowarp-aframe.js` を unsandboxed custom extension と
64
72
  package として参照する場合は version を固定します。
65
73
 
66
74
  ```bash
67
- pnpm add --save-exact @kubohiroya/turbowarp-aframe@0.3.0
75
+ pnpm add --save-exact @kubohiroya/turbowarp-aframe@0.5.0
68
76
  ```
69
77
 
70
78
  ## ブロック概要
@@ -118,7 +126,7 @@ pnpm add --save-exact @kubohiroya/turbowarp-aframe@0.3.0
118
126
 
119
127
  ## キーフレームアニメーション
120
128
 
121
- animation ブロックは clip 定義を保存し、A-Frame と Three.js が利用可能な場合に `AFRAME.THREE.AnimationMixer` で一致 node の root `object3D` へ再生します。`VectorKeyframeTrack` は `.position` と `.scale`、`QuaternionKeyframeTrack` は `.quaternion` を対象にします。glTF 内部の bone、child object、material property は初期スコープ外です。
129
+ animation ブロックは clip 定義を保存し、A-Frame と Three.js が利用可能な場合に `AFRAME.THREE.AnimationMixer` で一致 node の root `object3D` へ再生します。`VectorKeyframeTrack` は `.position` と `.scale`、`QuaternionKeyframeTrack` は `.quaternion` を対象にします。glTF 内部の bone、child object、material property は初期スコープ外です。VRMのヒューマノイドのボーンは、animation clipではなくVRMのブロックで回します。
122
130
 
123
131
  CSV 形式の track ブロックは Three.js に近い低レベル API です。教材や通常のブロック制作では、`add position keyframe...`、`add scale keyframe...`、`add euler rotation keyframe...` のように 1 keyframe ずつ追加するブロックを使います。同じ clip、同じ path、同じ time の keyframe は後から追加した値で置き換えます。
124
132
 
@@ -149,3 +157,5 @@ pnpm run check
149
157
  ## ライセンス
150
158
 
151
159
  SPDX-License-Identifier: MPL-2.0
160
+
161
+ bundleはMIT Licenseの`@pixiv/three-vrm`を含みます。[THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md)を参照してください。
package/README.md CHANGED
@@ -22,18 +22,18 @@ It treats TurboWarp sprites and backdrops as places to run 3D scene logic, not a
22
22
  - Node.js 22 or newer
23
23
  - Corepack-managed pnpm
24
24
  - TurboWarp unsandboxed extension support
25
- - A-Frame loaded by the host page or project environment before using the generated extension in a browser
25
+ - Network access to jsDelivr, from which `create 3D scene` loads A-Frame 1.8.0 pinned by version and subresource integrity; a page that already has A-Frame 1.8.0, such as an offline venue serving its own copy, loads nothing, and any other A-Frame version on the page is refused
26
26
 
27
27
  Unsandboxed extensions can manipulate the containing page. Load only generated extension bundles that you trust.
28
28
 
29
29
  ## Runtime scene capability
30
30
 
31
- Composite unsandboxed extensions can use the same scene operations as the blocks through the versioned runtime capability. Read `Scratch.vm.runtime.turbowarpAFrameCapability`, call `requireVersion(1)`, and then use these synchronous methods:
31
+ Composite unsandboxed extensions can use the same scene operations as the blocks through the versioned runtime capability. Read `Scratch.vm.runtime.turbowarpAFrameCapability`, call `requireVersion(2)`, and use the object it returns. Version 2 is the only version; version 1 was removed in 0.4.0, and requesting any other version throws.
32
32
 
33
33
  ```ts
34
- interface AFrameRuntimeCapabilityV1 {
35
- readonly version: 1;
36
- requireVersion(version: number): AFrameRuntimeCapabilityV1;
34
+ interface AFrameRuntimeCapabilityV2 {
35
+ readonly version: 2;
36
+ requireVersion(version: number): AFrameRuntimeCapabilityV2;
37
37
  loadTemplate(id: string, source: string): void;
38
38
  createFromTemplate(template: string, instance: string, parent: string): void;
39
39
  setPosition(selector: string, x: number, y: number, z: number): void;
@@ -41,10 +41,18 @@ interface AFrameRuntimeCapabilityV1 {
41
41
  emitEvent(type: string, selector: string, data: string): void;
42
42
  deleteSelector(selector: string): void;
43
43
  countSelector(selector: string): number;
44
+ loadVrm(url: string, selector: string): Promise<void>;
45
+ setVrmBoneRotation(selector: string, bone: string, x: number, y: number, z: number): void;
46
+ vrmBoneNames(selector: string): string[];
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[];
44
50
  }
45
51
  ```
46
52
 
47
- The capability deliberately exposes declarative templates and selectors, 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.
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.
54
+
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.
48
56
 
49
57
  ## Install
50
58
 
@@ -64,7 +72,7 @@ Load `dist/turbowarp-aframe.js` as an unsandboxed custom extension in TurboWarp.
64
72
  For package-based reuse, pin the version:
65
73
 
66
74
  ```bash
67
- pnpm add --save-exact @kubohiroya/turbowarp-aframe@0.3.0
75
+ pnpm add --save-exact @kubohiroya/turbowarp-aframe@0.5.0
68
76
  ```
69
77
 
70
78
  ## Block reference
@@ -73,7 +81,7 @@ pnpm add --save-exact @kubohiroya/turbowarp-aframe@0.3.0
73
81
 
74
82
  ### `create 3D scene with layer [LAYER] mode [MODE]`
75
83
 
76
- Initializes the A-Frame scene host and emits the scene ready event.
84
+ Loads A-Frame 1.8.0 from jsDelivr when the page does not have it, initializes the A-Frame scene host, and emits the scene ready event.
77
85
 
78
86
  | Property | Value |
79
87
  |---|---|
@@ -424,6 +432,73 @@ Reports whether any matching node has the stored 3D animation clip playing.
424
432
  | `CLIP` | String, default: `wave` |
425
433
  | `SELECTOR` | String, default: `#leftArm` |
426
434
 
435
+ ### `load VRM [URL] onto [SELECTOR]`
436
+
437
+ Loads a VRM avatar with three-vrm on the A-Frame Three.js and attaches it to the first matching node. The block waits until the model is ready.
438
+
439
+ | Property | Value |
440
+ |---|---|
441
+ | Type | Command |
442
+ | Opcode | `loadVrm` |
443
+ | `URL` | String, default: `avatar.vrm` |
444
+ | `SELECTOR` | String, default: `#avatar` |
445
+
446
+ ### `set VRM [SELECTOR] bone [BONE] rotation x [X] y [Y] z [Z]`
447
+
448
+ Sets the Euler rotation in degrees of a normalized VRM humanoid bone, relative to the T-pose, on every matching node whose VRM is ready.
449
+
450
+ | Property | Value |
451
+ |---|---|
452
+ | Type | Command |
453
+ | Opcode | `setVrmBoneRotation` |
454
+ | `SELECTOR` | String, default: `#avatar` |
455
+ | `BONE` | String, default: `leftUpperArm` |
456
+ | `X` | Number, default: `0` |
457
+ | `Y` | Number, default: `0` |
458
+ | `Z` | Number, default: `-60` |
459
+
460
+ ### `VRM [SELECTOR] humanoid bones`
461
+
462
+ Returns the humanoid bone names of the first matching node's VRM as a JSON array.
463
+
464
+ | Property | Value |
465
+ |---|---|
466
+ | Type | Reporter |
467
+ | Opcode | `vrmBoneNames` |
468
+ | `SELECTOR` | String, default: `#avatar` |
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
+
492
+ ### `VRM [SELECTOR] state`
493
+
494
+ Returns none, loading, ready, or error with its reason for the first matching node.
495
+
496
+ | Property | Value |
497
+ |---|---|
498
+ | Type | Reporter |
499
+ | Opcode | `vrmState` |
500
+ | `SELECTOR` | String, default: `#avatar` |
501
+
427
502
  <!-- END GENERATED BLOCKS -->
428
503
 
429
504
  ## Scene model
@@ -442,7 +517,7 @@ When a selector matches multiple nodes, command blocks apply to all matches. Blo
442
517
 
443
518
  ## Keyframe animations
444
519
 
445
- Animation blocks create stored clip definitions and play them on matching node root `object3D` instances through `AFRAME.THREE.AnimationMixer` when A-Frame and Three.js are available. `VectorKeyframeTrack` supports `.position` and `.scale`; `QuaternionKeyframeTrack` supports `.quaternion`. glTF internals such as bones, child objects, and material properties are outside the initial scope.
520
+ Animation blocks create stored clip definitions and play them on matching node root `object3D` instances through `AFRAME.THREE.AnimationMixer` when A-Frame and Three.js are available. `VectorKeyframeTrack` supports `.position` and `.scale`; `QuaternionKeyframeTrack` supports `.quaternion`. glTF internals such as bones, child objects, and material properties are outside the initial scope. VRM humanoid bones are turned by the VRM blocks rather than by animation clips.
446
521
 
447
522
  The CSV track blocks are low-level APIs that stay close to Three.js. Classroom and ordinary block projects should prefer the single-keyframe blocks: `add position keyframe...`, `add scale keyframe...`, and `add euler rotation keyframe...`. A keyframe with the same clip, path, and time replaces the earlier value.
448
523
 
@@ -480,3 +555,5 @@ pnpm run check
480
555
  ## License
481
556
 
482
557
  SPDX-License-Identifier: MPL-2.0
558
+
559
+ The bundle includes `@pixiv/three-vrm` under the MIT License; see [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md).
@@ -0,0 +1,17 @@
1
+ # Third-party notices
2
+
3
+ `dist/turbowarp-aframe.js` bundles `@pixiv/three-vrm` 3.5.5 to load VRM avatars. It includes
4
+ `@pixiv/three-vrm-core`, `@pixiv/three-vrm-materials-mtoon`,
5
+ `@pixiv/three-vrm-materials-hdr-emissive-multiplier`, `@pixiv/three-vrm-materials-v0compat`,
6
+ `@pixiv/three-vrm-node-constraint`, and `@pixiv/three-vrm-springbone` of the same version.
7
+ Copyright (c) 2019-2026 pixiv Inc. They are distributed under the MIT License, and their license
8
+ banners are kept in the bundle:
9
+
10
+ - <https://github.com/pixiv/three-vrm>
11
+ - <https://github.com/pixiv/three-vrm/blob/release/LICENSE>
12
+
13
+ A-Frame 1.8.0 is not bundled. The extension loads it at runtime from jsDelivr, pinned by version
14
+ and subresource integrity, unless the page already has it. A-Frame is distributed under the MIT
15
+ License:
16
+
17
+ - <https://github.com/aframevr/aframe>
@@ -313,6 +313,20 @@
313
313
  }
314
314
  ]
315
315
  },
316
+ {
317
+ "opcode": "loadVrm",
318
+ "blockType": "COMMAND",
319
+ "arguments": [
320
+ {
321
+ "id": "SELECTOR",
322
+ "type": "STRING"
323
+ },
324
+ {
325
+ "id": "URL",
326
+ "type": "STRING"
327
+ }
328
+ ]
329
+ },
316
330
  {
317
331
  "opcode": "moveBy",
318
332
  "blockType": "COMMAND",
@@ -479,6 +493,50 @@
479
493
  }
480
494
  ]
481
495
  },
496
+ {
497
+ "opcode": "setVrmBoneRotation",
498
+ "blockType": "COMMAND",
499
+ "arguments": [
500
+ {
501
+ "id": "BONE",
502
+ "type": "STRING"
503
+ },
504
+ {
505
+ "id": "SELECTOR",
506
+ "type": "STRING"
507
+ },
508
+ {
509
+ "id": "X",
510
+ "type": "NUMBER"
511
+ },
512
+ {
513
+ "id": "Y",
514
+ "type": "NUMBER"
515
+ },
516
+ {
517
+ "id": "Z",
518
+ "type": "NUMBER"
519
+ }
520
+ ]
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
+ },
482
540
  {
483
541
  "opcode": "stopAnimationClip",
484
542
  "blockType": "COMMAND",
@@ -493,6 +551,36 @@
493
551
  }
494
552
  ]
495
553
  },
554
+ {
555
+ "opcode": "vrmBoneNames",
556
+ "blockType": "REPORTER",
557
+ "arguments": [
558
+ {
559
+ "id": "SELECTOR",
560
+ "type": "STRING"
561
+ }
562
+ ]
563
+ },
564
+ {
565
+ "opcode": "vrmExpressionNames",
566
+ "blockType": "REPORTER",
567
+ "arguments": [
568
+ {
569
+ "id": "SELECTOR",
570
+ "type": "STRING"
571
+ }
572
+ ]
573
+ },
574
+ {
575
+ "opcode": "vrmState",
576
+ "blockType": "REPORTER",
577
+ "arguments": [
578
+ {
579
+ "id": "SELECTOR",
580
+ "type": "STRING"
581
+ }
582
+ ]
583
+ },
496
584
  {
497
585
  "opcode": "whenEventOnSelector",
498
586
  "blockType": "HAT",