@kubohiroya/turbowarp-aframe 0.6.0 → 0.7.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 +6 -1
- package/README.md +6 -1
- package/dist/turbowarp-aframe.js +25 -0
- package/docs/architecture.ja.md +1 -1
- package/docs/architecture.md +1 -1
- package/package.json +1 -1
- package/src/extension.ts +3 -0
- package/src/runtime-capability.ts +17 -0
package/README.ja.md
CHANGED
|
@@ -34,6 +34,9 @@ unsandboxed 拡張はページ DOM を操作できます。信頼できる生成
|
|
|
34
34
|
interface AFrameRuntimeCapabilityV2 {
|
|
35
35
|
readonly version: 2;
|
|
36
36
|
requireVersion(version: number): AFrameRuntimeCapabilityV2;
|
|
37
|
+
createScene(layer: string, mode: string): Promise<void>;
|
|
38
|
+
createNode(type: string, id: string, parent: string): void;
|
|
39
|
+
addClass(className: string, selector: string): void;
|
|
37
40
|
loadTemplate(id: string, source: string): void;
|
|
38
41
|
createFromTemplate(template: string, instance: string, parent: string): void;
|
|
39
42
|
setPosition(selector: string, x: number, y: number, z: number): void;
|
|
@@ -52,6 +55,8 @@ interface AFrameRuntimeCapabilityV2 {
|
|
|
52
55
|
}
|
|
53
56
|
```
|
|
54
57
|
|
|
58
|
+
`createScene`、`createNode`、`addClass`はscene自体を構築します。scene記述をA-Frame nodeへ変換する機能拡張が、blockだけに頼らずこのportを通せるようにするためです。`createFromTemplate`は代用になりません。子のidにinstance idを前置し、`template`と`instance`のdata keyを書き込むため、自分でidを決めている呼び出し側は要求したidを得られません。
|
|
59
|
+
|
|
55
60
|
`setAttribute`と`setData`は、`visible`などのA-Frameコンポーネント属性と`data-<key>`属性を、selectorに一致するすべてのnodeへ書きます。属性を書く必要のある連携機能拡張—たとえばtarget poseとvisibilityを書く`turbowarp-ar`—が、機能拡張の背後でDOMを直接触らずこのportを通り、機能拡張が持つscene stateと矛盾しないようにするために存在します。
|
|
56
61
|
|
|
57
62
|
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`はモデルが持つ表情名を返し、存在しない名前は例外になります。
|
|
@@ -76,7 +81,7 @@ TurboWarp では `dist/turbowarp-aframe.js` を unsandboxed custom extension と
|
|
|
76
81
|
package として参照する場合は version を固定します。
|
|
77
82
|
|
|
78
83
|
```bash
|
|
79
|
-
pnpm add --save-exact @kubohiroya/turbowarp-aframe@0.
|
|
84
|
+
pnpm add --save-exact @kubohiroya/turbowarp-aframe@0.7.0
|
|
80
85
|
```
|
|
81
86
|
|
|
82
87
|
## ブロック概要
|
package/README.md
CHANGED
|
@@ -34,6 +34,9 @@ Composite unsandboxed extensions can use the same scene operations as the blocks
|
|
|
34
34
|
interface AFrameRuntimeCapabilityV2 {
|
|
35
35
|
readonly version: 2;
|
|
36
36
|
requireVersion(version: number): AFrameRuntimeCapabilityV2;
|
|
37
|
+
createScene(layer: string, mode: string): Promise<void>;
|
|
38
|
+
createNode(type: string, id: string, parent: string): void;
|
|
39
|
+
addClass(className: string, selector: string): void;
|
|
37
40
|
loadTemplate(id: string, source: string): void;
|
|
38
41
|
createFromTemplate(template: string, instance: string, parent: string): void;
|
|
39
42
|
setPosition(selector: string, x: number, y: number, z: number): void;
|
|
@@ -52,6 +55,8 @@ interface AFrameRuntimeCapabilityV2 {
|
|
|
52
55
|
}
|
|
53
56
|
```
|
|
54
57
|
|
|
58
|
+
`createScene`, `createNode`, and `addClass` build the scene itself, so an extension that turns a scene description into A-Frame nodes can do it through this port rather than only through blocks. `createFromTemplate` is not a substitute: it prefixes child ids with the instance id and writes `template` and `instance` data keys, so a caller that already owns its ids would not get the ids it asked for.
|
|
59
|
+
|
|
55
60
|
`setAttribute` and `setData` write an A-Frame component attribute such as `visible`, and a `data-<key>` attribute, on every matching node. They exist so that a companion extension which has to write attributes, such as `turbowarp-ar` writing target pose and visibility, goes through this port and keeps the extension's scene state in sync, instead of reaching into the DOM behind its back.
|
|
56
61
|
|
|
57
62
|
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.
|
|
@@ -76,7 +81,7 @@ Load `dist/turbowarp-aframe.js` as an unsandboxed custom extension in TurboWarp.
|
|
|
76
81
|
For package-based reuse, pin the version:
|
|
77
82
|
|
|
78
83
|
```bash
|
|
79
|
-
pnpm add --save-exact @kubohiroya/turbowarp-aframe@0.
|
|
84
|
+
pnpm add --save-exact @kubohiroya/turbowarp-aframe@0.7.0
|
|
80
85
|
```
|
|
81
86
|
|
|
82
87
|
## Block reference
|
package/dist/turbowarp-aframe.js
CHANGED
|
@@ -685,6 +685,18 @@
|
|
|
685
685
|
var runtimeCapabilityKey = "turbowarpAFrameCapability";
|
|
686
686
|
function createRuntimeCapability(scene, assertActive) {
|
|
687
687
|
const scenePort = {
|
|
688
|
+
async createScene(layer, mode) {
|
|
689
|
+
assertActive();
|
|
690
|
+
await scene.createScene(layer, mode);
|
|
691
|
+
},
|
|
692
|
+
createNode(type, id, parent) {
|
|
693
|
+
assertActive();
|
|
694
|
+
scene.createNode(type, id, parent);
|
|
695
|
+
},
|
|
696
|
+
addClass(className, selector) {
|
|
697
|
+
assertActive();
|
|
698
|
+
scene.addClass(className, selector);
|
|
699
|
+
},
|
|
688
700
|
loadTemplate(id, source) {
|
|
689
701
|
assertActive();
|
|
690
702
|
scene.loadTemplate(id, source);
|
|
@@ -7027,6 +7039,19 @@
|
|
|
7027
7039
|
this.vrms = new VrmAvatars(() => this.getThree());
|
|
7028
7040
|
this.resetGraph();
|
|
7029
7041
|
this.runtimeCapability = createRuntimeCapability({
|
|
7042
|
+
createScene: (layer, mode) => this.createScene({
|
|
7043
|
+
LAYER: layer,
|
|
7044
|
+
MODE: mode
|
|
7045
|
+
}),
|
|
7046
|
+
createNode: (type, id, parent) => this.createNode({
|
|
7047
|
+
TYPE: type,
|
|
7048
|
+
ID: id,
|
|
7049
|
+
PARENT: parent
|
|
7050
|
+
}),
|
|
7051
|
+
addClass: (className, selector) => this.addClass({
|
|
7052
|
+
CLASS: className,
|
|
7053
|
+
SELECTOR: selector
|
|
7054
|
+
}),
|
|
7030
7055
|
loadTemplate: (id, source) => this.loadTemplate({
|
|
7031
7056
|
ID: id,
|
|
7032
7057
|
SOURCE: source
|
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`、`setAttribute`、`setData`、`emitEvent`、`deleteSelector`、`countSelector`に、`loadVrm`、`setVrmBoneRotation`、`vrmBoneNames`、`vrmStatus`、`setVrmExpression`、`vrmExpressionNames`を加えた、freezeされた狭い型付きportです。scene操作だけを持っていたversion 1は、version 2と並べて残さず0.4.0で撤去しました。正しく保つ契約を1つにするためです。表情の操作と、後から加えた`setAttribute`・`setData`は、methodを加えるだけでconsumerは使うmethodの有無を確かめるため、versionを変えずにversion 2へ加えました。`setAttribute`と`setData`は、A-Frame属性を書く必要のある連携機能拡張—たとえばtarget poseとvisibilityを書く`turbowarp-ar`—が、機能拡張の背後でDOMを直接触らずこのport
|
|
27
|
+
機能拡張は`Scratch.vm.runtime.turbowarpAFrameCapability`を公開します。version 2は、`createScene`、`createNode`、`addClass`、`loadTemplate`、`createFromTemplate`、`setPosition`、`setRotation`、`setAttribute`、`setData`、`emitEvent`、`deleteSelector`、`countSelector`に、`loadVrm`、`setVrmBoneRotation`、`vrmBoneNames`、`vrmStatus`、`setVrmExpression`、`vrmExpressionNames`を加えた、freezeされた狭い型付きportです。scene操作だけを持っていたversion 1は、version 2と並べて残さず0.4.0で撤去しました。正しく保つ契約を1つにするためです。表情の操作と、後から加えた`setAttribute`・`setData`は、methodを加えるだけでconsumerは使うmethodの有無を確かめるため、versionを変えずにversion 2へ加えました。`setAttribute`と`setData`は、A-Frame属性を書く必要のある連携機能拡張—たとえばtarget poseとvisibilityを書く`turbowarp-ar`—が、機能拡張の背後でDOMを直接触らずこのportを通るようにするために存在します。`createScene`、`createNode`、`addClass`はその組を完成させ、記述からsceneを丸ごと構築する機能拡張がblockだけに頼らずportを通せるようにします。`createFromTemplate`では代用できません。子のidにinstance idを前置し、`template`と`instance`のdata keyを書き込むためで、自分でidを決める呼び出し側はそれを望みません。
|
|
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`, `setAttribute`, `setData`, `emitEvent`, `deleteSelector`, and `countSelector`, plus `loadVrm`, `setVrmBoneRotation`, `vrmBoneNames`, `vrmStatus`, `setVrmExpression`, and `vrmExpressionNames`. The expression operations, and later `setAttribute` and `setData`, were added to version 2 without changing its version, because they only add methods and a consumer checks for the methods it uses. `setAttribute` and `setData` exist so that a companion extension which needs to write A-Frame attributes, such as `turbowarp-ar` writing target pose and visibility, goes through this port instead of reaching into the DOM behind the extension's back. 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.
|
|
27
|
+
The extension publishes `Scratch.vm.runtime.turbowarpAFrameCapability`. Version 2 is a narrow typed, frozen port containing `createScene`, `createNode`, `addClass`, `loadTemplate`, `createFromTemplate`, `setPosition`, `setRotation`, `setAttribute`, `setData`, `emitEvent`, `deleteSelector`, and `countSelector`, plus `loadVrm`, `setVrmBoneRotation`, `vrmBoneNames`, `vrmStatus`, `setVrmExpression`, and `vrmExpressionNames`. The expression operations, and later `setAttribute` and `setData`, were added to version 2 without changing its version, because they only add methods and a consumer checks for the methods it uses. `setAttribute` and `setData` exist so that a companion extension which needs to write A-Frame attributes, such as `turbowarp-ar` writing target pose and visibility, goes through this port instead of reaching into the DOM behind the extension's back. `createScene`, `createNode`, and `addClass` complete the set, so an extension that builds a whole scene from a description can do it through the port rather than only through blocks; `createFromTemplate` cannot stand in for them, because it prefixes child ids with the instance id and writes `template` and `instance` data keys, which a caller that owns its own ids does not want. 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
package/src/extension.ts
CHANGED
|
@@ -171,6 +171,9 @@ export class TurboWarpAFrameExtension implements TurboWarpExtension {
|
|
|
171
171
|
this.resetGraph();
|
|
172
172
|
this.runtimeCapability = createRuntimeCapability(
|
|
173
173
|
{
|
|
174
|
+
createScene: (layer, mode) => this.createScene({LAYER: layer, MODE: mode}),
|
|
175
|
+
createNode: (type, id, parent) => this.createNode({TYPE: type, ID: id, PARENT: parent}),
|
|
176
|
+
addClass: (className, selector) => this.addClass({CLASS: className, SELECTOR: selector}),
|
|
174
177
|
loadTemplate: (id, source) => this.loadTemplate({ID: id, SOURCE: source}),
|
|
175
178
|
createFromTemplate: (template, instance, parent) =>
|
|
176
179
|
this.createFromTemplate({TEMPLATE: template, INSTANCE: instance, PARENT: parent}),
|
|
@@ -3,6 +3,11 @@ export const runtimeCapabilityVersion = 2 as const;
|
|
|
3
3
|
export const runtimeCapabilityKey = 'turbowarpAFrameCapability';
|
|
4
4
|
|
|
5
5
|
export interface AFrameScenePort {
|
|
6
|
+
/** Creates the scene host, loading A-Frame first when the page does not have it. */
|
|
7
|
+
createScene(layer: string, mode: string): Promise<void>;
|
|
8
|
+
/** Adds one node under the node the parent selector matches. */
|
|
9
|
+
createNode(type: string, id: string, parent: string): void;
|
|
10
|
+
addClass(className: string, selector: string): void;
|
|
6
11
|
loadTemplate(id: string, source: string): void;
|
|
7
12
|
createFromTemplate(template: string, instance: string, parent: string): void;
|
|
8
13
|
setPosition(selector: string, x: number, y: number, z: number): void;
|
|
@@ -45,6 +50,18 @@ export function createRuntimeCapability(
|
|
|
45
50
|
assertActive: () => void
|
|
46
51
|
): AFrameRuntimeCapabilityV2 {
|
|
47
52
|
const scenePort: AFrameScenePort = {
|
|
53
|
+
async createScene(layer, mode) {
|
|
54
|
+
assertActive();
|
|
55
|
+
await scene.createScene(layer, mode);
|
|
56
|
+
},
|
|
57
|
+
createNode(type, id, parent) {
|
|
58
|
+
assertActive();
|
|
59
|
+
scene.createNode(type, id, parent);
|
|
60
|
+
},
|
|
61
|
+
addClass(className, selector) {
|
|
62
|
+
assertActive();
|
|
63
|
+
scene.addClass(className, selector);
|
|
64
|
+
},
|
|
48
65
|
loadTemplate(id, source) {
|
|
49
66
|
assertActive();
|
|
50
67
|
scene.loadTemplate(id, source);
|