@kubohiroya/turbowarp-aframe 0.2.0 → 0.4.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,10 +22,36 @@ 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
+ ## runtime scene capability
30
+
31
+ 複合的なunsandboxed機能拡張は、version付きruntime capabilityを通じてブロックと同じscene操作を利用できます。`Scratch.vm.runtime.turbowarpAFrameCapability`を取得し、`requireVersion(2)`を呼んで、返ったオブジェクトを利用します。versionは2だけです。version 1は0.4.0で撤去し、それ以外のversionを要求すると例外になります。
32
+
33
+ ```ts
34
+ interface AFrameRuntimeCapabilityV2 {
35
+ readonly version: 2;
36
+ requireVersion(version: number): AFrameRuntimeCapabilityV2;
37
+ loadTemplate(id: string, source: string): void;
38
+ createFromTemplate(template: string, instance: string, parent: string): void;
39
+ setPosition(selector: string, x: number, y: number, z: number): void;
40
+ setRotation(selector: string, x: number, y: number, z: number): void;
41
+ emitEvent(type: string, selector: string, data: string): void;
42
+ deleteSelector(selector: string): void;
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
+ }
49
+ ```
50
+
51
+ version 2は、scene操作に加えてVRMアバターを扱います。`loadVrm`は、A-Frameが読み込んだThree.jsの上でthree-vrmを動かし、selectorに最初に一致したnodeへモデルを読み込んで、準備ができると解決します。`setVrmBoneRotation`は、`leftUpperArm`などの正規化されたヒューマノイドのボーンへ、Tポーズからの回転を度のEuler角で設定します。どのVRMでも同じ回転が同じ意味になり、sceneのtickがモデル本来のボーンへ反映します。VRMの準備ができていないnodeは飛ばし、存在しないボーン名は例外になります。
52
+
53
+ このcapabilityが公開するのは宣言的template、selector、ヒューマノイドのボーン名だけです。private DOM node、A-Frame object、Three.js object、glTF内部実装は公開しません。未対応versionはfail closedし、機能拡張のdispose後に保持されたcapabilityを呼び出した場合も、すべて明示的に拒否します。
54
+
29
55
  ## インストール
30
56
 
31
57
  ```bash
@@ -44,7 +70,7 @@ TurboWarp では `dist/turbowarp-aframe.js` を unsandboxed custom extension と
44
70
  package として参照する場合は version を固定します。
45
71
 
46
72
  ```bash
47
- pnpm add --save-exact @kubohiroya/turbowarp-aframe@0.2.0
73
+ pnpm add --save-exact @kubohiroya/turbowarp-aframe@0.4.0
48
74
  ```
49
75
 
50
76
  ## ブロック概要
@@ -98,7 +124,7 @@ pnpm add --save-exact @kubohiroya/turbowarp-aframe@0.2.0
98
124
 
99
125
  ## キーフレームアニメーション
100
126
 
101
- animation ブロックは clip 定義を保存し、A-Frame と Three.js が利用可能な場合に `AFRAME.THREE.AnimationMixer` で一致 node の root `object3D` へ再生します。`VectorKeyframeTrack` は `.position` と `.scale`、`QuaternionKeyframeTrack` は `.quaternion` を対象にします。glTF 内部の bone、child object、material property は初期スコープ外です。
127
+ 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のブロックで回します。
102
128
 
103
129
  CSV 形式の track ブロックは Three.js に近い低レベル API です。教材や通常のブロック制作では、`add position keyframe...`、`add scale keyframe...`、`add euler rotation keyframe...` のように 1 keyframe ずつ追加するブロックを使います。同じ clip、同じ path、同じ time の keyframe は後から追加した値で置き換えます。
104
130
 
@@ -129,3 +155,5 @@ pnpm run check
129
155
  ## ライセンス
130
156
 
131
157
  SPDX-License-Identifier: MPL-2.0
158
+
159
+ bundleはMIT Licenseの`@pixiv/three-vrm`を含みます。[THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md)を参照してください。
package/README.md CHANGED
@@ -22,10 +22,36 @@ 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
+ ## Runtime scene capability
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(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
+
33
+ ```ts
34
+ interface AFrameRuntimeCapabilityV2 {
35
+ readonly version: 2;
36
+ requireVersion(version: number): AFrameRuntimeCapabilityV2;
37
+ loadTemplate(id: string, source: string): void;
38
+ createFromTemplate(template: string, instance: string, parent: string): void;
39
+ setPosition(selector: string, x: number, y: number, z: number): void;
40
+ setRotation(selector: string, x: number, y: number, z: number): void;
41
+ emitEvent(type: string, selector: string, data: string): void;
42
+ deleteSelector(selector: string): void;
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
+ }
49
+ ```
50
+
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.
52
+
53
+ 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
+
29
55
  ## Install
30
56
 
31
57
  ```bash
@@ -44,7 +70,7 @@ Load `dist/turbowarp-aframe.js` as an unsandboxed custom extension in TurboWarp.
44
70
  For package-based reuse, pin the version:
45
71
 
46
72
  ```bash
47
- pnpm add --save-exact @kubohiroya/turbowarp-aframe@0.2.0
73
+ pnpm add --save-exact @kubohiroya/turbowarp-aframe@0.4.0
48
74
  ```
49
75
 
50
76
  ## Block reference
@@ -53,7 +79,7 @@ pnpm add --save-exact @kubohiroya/turbowarp-aframe@0.2.0
53
79
 
54
80
  ### `create 3D scene with layer [LAYER] mode [MODE]`
55
81
 
56
- Initializes the A-Frame scene host and emits the scene ready event.
82
+ 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.
57
83
 
58
84
  | Property | Value |
59
85
  |---|---|
@@ -404,6 +430,51 @@ Reports whether any matching node has the stored 3D animation clip playing.
404
430
  | `CLIP` | String, default: `wave` |
405
431
  | `SELECTOR` | String, default: `#leftArm` |
406
432
 
433
+ ### `load VRM [URL] onto [SELECTOR]`
434
+
435
+ 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.
436
+
437
+ | Property | Value |
438
+ |---|---|
439
+ | Type | Command |
440
+ | Opcode | `loadVrm` |
441
+ | `URL` | String, default: `avatar.vrm` |
442
+ | `SELECTOR` | String, default: `#avatar` |
443
+
444
+ ### `set VRM [SELECTOR] bone [BONE] rotation x [X] y [Y] z [Z]`
445
+
446
+ 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.
447
+
448
+ | Property | Value |
449
+ |---|---|
450
+ | Type | Command |
451
+ | Opcode | `setVrmBoneRotation` |
452
+ | `SELECTOR` | String, default: `#avatar` |
453
+ | `BONE` | String, default: `leftUpperArm` |
454
+ | `X` | Number, default: `0` |
455
+ | `Y` | Number, default: `0` |
456
+ | `Z` | Number, default: `-60` |
457
+
458
+ ### `VRM [SELECTOR] humanoid bones`
459
+
460
+ Returns the humanoid bone names of the first matching node's VRM as a JSON array.
461
+
462
+ | Property | Value |
463
+ |---|---|
464
+ | Type | Reporter |
465
+ | Opcode | `vrmBoneNames` |
466
+ | `SELECTOR` | String, default: `#avatar` |
467
+
468
+ ### `VRM [SELECTOR] state`
469
+
470
+ Returns none, loading, ready, or error with its reason for the first matching node.
471
+
472
+ | Property | Value |
473
+ |---|---|
474
+ | Type | Reporter |
475
+ | Opcode | `vrmState` |
476
+ | `SELECTOR` | String, default: `#avatar` |
477
+
407
478
  <!-- END GENERATED BLOCKS -->
408
479
 
409
480
  ## Scene model
@@ -422,7 +493,7 @@ When a selector matches multiple nodes, command blocks apply to all matches. Blo
422
493
 
423
494
  ## Keyframe animations
424
495
 
425
- 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.
496
+ 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.
426
497
 
427
498
  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.
428
499
 
@@ -460,3 +531,5 @@ pnpm run check
460
531
  ## License
461
532
 
462
533
  SPDX-License-Identifier: MPL-2.0
534
+
535
+ 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,32 @@
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
+ },
482
522
  {
483
523
  "opcode": "stopAnimationClip",
484
524
  "blockType": "COMMAND",
@@ -493,6 +533,26 @@
493
533
  }
494
534
  ]
495
535
  },
536
+ {
537
+ "opcode": "vrmBoneNames",
538
+ "blockType": "REPORTER",
539
+ "arguments": [
540
+ {
541
+ "id": "SELECTOR",
542
+ "type": "STRING"
543
+ }
544
+ ]
545
+ },
546
+ {
547
+ "opcode": "vrmState",
548
+ "blockType": "REPORTER",
549
+ "arguments": [
550
+ {
551
+ "id": "SELECTOR",
552
+ "type": "STRING"
553
+ }
554
+ ]
555
+ },
496
556
  {
497
557
  "opcode": "whenEventOnSelector",
498
558
  "blockType": "HAT",