@kubohiroya/turbowarp-aframe 0.5.0 → 0.6.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 +5 -1
- package/README.md +5 -1
- package/dist/turbowarp-aframe.js +41 -3
- package/docs/architecture.ja.md +5 -4
- package/docs/architecture.md +5 -4
- package/package.json +1 -1
- package/src/extension.ts +37 -4
- package/src/runtime-capability.ts +12 -0
package/README.ja.md
CHANGED
|
@@ -38,6 +38,8 @@ interface AFrameRuntimeCapabilityV2 {
|
|
|
38
38
|
createFromTemplate(template: string, instance: string, parent: string): void;
|
|
39
39
|
setPosition(selector: string, x: number, y: number, z: number): void;
|
|
40
40
|
setRotation(selector: string, x: number, y: number, z: number): void;
|
|
41
|
+
setAttribute(selector: string, name: string, value: string): void;
|
|
42
|
+
setData(selector: string, key: string, value: string): void;
|
|
41
43
|
emitEvent(type: string, selector: string, data: string): void;
|
|
42
44
|
deleteSelector(selector: string): void;
|
|
43
45
|
countSelector(selector: string): number;
|
|
@@ -50,6 +52,8 @@ interface AFrameRuntimeCapabilityV2 {
|
|
|
50
52
|
}
|
|
51
53
|
```
|
|
52
54
|
|
|
55
|
+
`setAttribute`と`setData`は、`visible`などのA-Frameコンポーネント属性と`data-<key>`属性を、selectorに一致するすべてのnodeへ書きます。属性を書く必要のある連携機能拡張—たとえばtarget poseとvisibilityを書く`turbowarp-ar`—が、機能拡張の背後でDOMを直接触らずこのportを通り、機能拡張が持つscene stateと矛盾しないようにするために存在します。
|
|
56
|
+
|
|
53
57
|
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
58
|
|
|
55
59
|
このcapabilityが公開するのは宣言的template、selector、ヒューマノイドのボーン名だけです。private DOM node、A-Frame object、Three.js object、glTF内部実装は公開しません。未対応versionはfail closedし、機能拡張のdispose後に保持されたcapabilityを呼び出した場合も、すべて明示的に拒否します。
|
|
@@ -72,7 +76,7 @@ TurboWarp では `dist/turbowarp-aframe.js` を unsandboxed custom extension と
|
|
|
72
76
|
package として参照する場合は version を固定します。
|
|
73
77
|
|
|
74
78
|
```bash
|
|
75
|
-
pnpm add --save-exact @kubohiroya/turbowarp-aframe@0.
|
|
79
|
+
pnpm add --save-exact @kubohiroya/turbowarp-aframe@0.6.0
|
|
76
80
|
```
|
|
77
81
|
|
|
78
82
|
## ブロック概要
|
package/README.md
CHANGED
|
@@ -38,6 +38,8 @@ interface AFrameRuntimeCapabilityV2 {
|
|
|
38
38
|
createFromTemplate(template: string, instance: string, parent: string): void;
|
|
39
39
|
setPosition(selector: string, x: number, y: number, z: number): void;
|
|
40
40
|
setRotation(selector: string, x: number, y: number, z: number): void;
|
|
41
|
+
setAttribute(selector: string, name: string, value: string): void;
|
|
42
|
+
setData(selector: string, key: string, value: string): void;
|
|
41
43
|
emitEvent(type: string, selector: string, data: string): void;
|
|
42
44
|
deleteSelector(selector: string): void;
|
|
43
45
|
countSelector(selector: string): number;
|
|
@@ -50,6 +52,8 @@ interface AFrameRuntimeCapabilityV2 {
|
|
|
50
52
|
}
|
|
51
53
|
```
|
|
52
54
|
|
|
55
|
+
`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
|
+
|
|
53
57
|
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
58
|
|
|
55
59
|
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.
|
|
@@ -72,7 +76,7 @@ Load `dist/turbowarp-aframe.js` as an unsandboxed custom extension in TurboWarp.
|
|
|
72
76
|
For package-based reuse, pin the version:
|
|
73
77
|
|
|
74
78
|
```bash
|
|
75
|
-
pnpm add --save-exact @kubohiroya/turbowarp-aframe@0.
|
|
79
|
+
pnpm add --save-exact @kubohiroya/turbowarp-aframe@0.6.0
|
|
76
80
|
```
|
|
77
81
|
|
|
78
82
|
## Block reference
|
package/dist/turbowarp-aframe.js
CHANGED
|
@@ -701,6 +701,14 @@
|
|
|
701
701
|
assertActive();
|
|
702
702
|
scene.setRotation(selector, x, y, z);
|
|
703
703
|
},
|
|
704
|
+
setAttribute(selector, name, value) {
|
|
705
|
+
assertActive();
|
|
706
|
+
scene.setAttribute(selector, name, value);
|
|
707
|
+
},
|
|
708
|
+
setData(selector, key, value) {
|
|
709
|
+
assertActive();
|
|
710
|
+
scene.setData(selector, key, value);
|
|
711
|
+
},
|
|
704
712
|
emitEvent(type, selector, data) {
|
|
705
713
|
assertActive();
|
|
706
714
|
scene.emitEvent(type, selector, data);
|
|
@@ -6970,6 +6978,18 @@
|
|
|
6970
6978
|
};
|
|
6971
6979
|
//#endregion
|
|
6972
6980
|
//#region src/extension.ts
|
|
6981
|
+
var SCENE_LAYERS = Object.freeze(["above-stage", "below-stage"]);
|
|
6982
|
+
var DEFAULT_SCENE_LAYER = "above-stage";
|
|
6983
|
+
/**
|
|
6984
|
+
* Stacking positions for the two hosts that can share the stage.
|
|
6985
|
+
*
|
|
6986
|
+
* `turbowarp-ar` puts its camera background one step below the `above-stage` value here, so a 3D
|
|
6987
|
+
* scene renders over the camera image. Keep the two in step when either extension changes.
|
|
6988
|
+
*/
|
|
6989
|
+
var SCENE_HOST_Z_INDEX = {
|
|
6990
|
+
"above-stage": "10",
|
|
6991
|
+
"below-stage": "0"
|
|
6992
|
+
};
|
|
6973
6993
|
var blockDefinitions = block_definitions_default.blocks;
|
|
6974
6994
|
var ROOT_ID = "scene";
|
|
6975
6995
|
var DOM_EVENT_TYPES = [
|
|
@@ -6997,7 +7017,7 @@
|
|
|
6997
7017
|
this.domEventTypes = new Set(DOM_EVENT_TYPES);
|
|
6998
7018
|
this.runtimeId = `twaframe-${Math.random().toString(36).slice(2)}`;
|
|
6999
7019
|
this.sceneOptions = {
|
|
7000
|
-
layer:
|
|
7020
|
+
layer: DEFAULT_SCENE_LAYER,
|
|
7001
7021
|
mode: "3d"
|
|
7002
7022
|
};
|
|
7003
7023
|
this.rootElement = null;
|
|
@@ -7028,6 +7048,16 @@
|
|
|
7028
7048
|
Y: y,
|
|
7029
7049
|
Z: z
|
|
7030
7050
|
}),
|
|
7051
|
+
setAttribute: (selector, name, value) => this.setAttribute({
|
|
7052
|
+
SELECTOR: selector,
|
|
7053
|
+
NAME: name,
|
|
7054
|
+
VALUE: value
|
|
7055
|
+
}),
|
|
7056
|
+
setData: (selector, key, value) => this.setData({
|
|
7057
|
+
SELECTOR: selector,
|
|
7058
|
+
KEY: key,
|
|
7059
|
+
VALUE: value
|
|
7060
|
+
}),
|
|
7031
7061
|
emitEvent: (type, selector, data) => this.emitEvent({
|
|
7032
7062
|
TYPE: type,
|
|
7033
7063
|
SELECTOR: selector,
|
|
@@ -7070,7 +7100,7 @@
|
|
|
7070
7100
|
async createScene(args) {
|
|
7071
7101
|
await ensureAFrame();
|
|
7072
7102
|
this.sceneOptions = {
|
|
7073
|
-
layer: Scratch.Cast.toString(args.LAYER)
|
|
7103
|
+
layer: this.normalizeLayer(Scratch.Cast.toString(args.LAYER)),
|
|
7074
7104
|
mode: Scratch.Cast.toString(args.MODE) || "3d"
|
|
7075
7105
|
};
|
|
7076
7106
|
this.resetGraph();
|
|
@@ -7498,7 +7528,7 @@
|
|
|
7498
7528
|
host.style.position = "absolute";
|
|
7499
7529
|
host.style.inset = "0";
|
|
7500
7530
|
host.style.pointerEvents = "auto";
|
|
7501
|
-
host.style.zIndex = this.sceneOptions.layer
|
|
7531
|
+
host.style.zIndex = SCENE_HOST_Z_INDEX[this.sceneOptions.layer];
|
|
7502
7532
|
const scene = document.createElement("a-scene");
|
|
7503
7533
|
host.append(scene);
|
|
7504
7534
|
this.findStageMount().append(host);
|
|
@@ -7872,6 +7902,14 @@
|
|
|
7872
7902
|
normalizeId(value) {
|
|
7873
7903
|
return this.normalizeToken(value) || "node";
|
|
7874
7904
|
}
|
|
7905
|
+
/**
|
|
7906
|
+
* Blocks take whatever string a project hands them, so an unknown layer falls back to the default
|
|
7907
|
+
* rather than stopping the script, and never reaches the host as a value it cannot honor.
|
|
7908
|
+
*/
|
|
7909
|
+
normalizeLayer(value) {
|
|
7910
|
+
const layer = value.trim();
|
|
7911
|
+
return SCENE_LAYERS.includes(layer) ? layer : DEFAULT_SCENE_LAYER;
|
|
7912
|
+
}
|
|
7875
7913
|
normalizeToken(value) {
|
|
7876
7914
|
return value.trim().replace(/[^a-zA-Z0-9_-]/g, "-");
|
|
7877
7915
|
}
|
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`、`setVrmExpression`、`vrmExpressionNames`を加えた、freezeされた狭い型付きportです。scene操作だけを持っていたversion 1は、version 2と並べて残さず0.4.0で撤去しました。正しく保つ契約を1
|
|
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を通るようにするために存在します。
|
|
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
|
|
|
@@ -36,13 +36,14 @@ consumerは利用前に`requireVersion(2)`を呼ぶ必要があります。1を
|
|
|
36
36
|
|
|
37
37
|
`createScene` は root の `#scene` ノードを作り、ブラウザ DOM がある場合は `#tw-aframe-root > a-scene` を作成します。host は最初に検出できた TurboWarp stage wrapper または canvas の親へ mount し、stage らしい要素が見つからない場合だけ `document.body` に fallback します。
|
|
38
38
|
|
|
39
|
-
|
|
39
|
+
layer の語彙は閉じており、`turbowarp-ar` もカメラ背景に同じ2つの値を使います。
|
|
40
40
|
|
|
41
41
|
- `above-stage`: A-Frame を TurboWarp stage の上に重ねます。
|
|
42
42
|
- `below-stage`: host CSS が許す場合に A-Frame を stage の背面へ置きます。
|
|
43
|
-
- `camera-under-3d`: camera/video を 3D layer の下に置く想定です。
|
|
44
43
|
|
|
45
|
-
|
|
44
|
+
block の引数は文字列のままなので作品は任意の値を渡せますが、認識できない値は `above-stage` へフォールバックします。host が honor できない値を layer として保持することはありません。`above-stage` のとき、host は `turbowarp-ar` のカメラ背景より1つ上の重なり位置に置かれ、3D scene がカメラ映像の上に描かれます。`camera-under-3d` はかつてここに記載されていましたが実装されたことはありません。それが表していた順序は構造であって、呼び出し側が指定できる値ではありません。
|
|
45
|
+
|
|
46
|
+
一方 mode は、意図を述べるだけの開いた文字列です。
|
|
46
47
|
|
|
47
48
|
- `3d`: 通常の埋め込み 3D シーンです。
|
|
48
49
|
- `camera`: camera 合成を想定します。
|
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`, `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.
|
|
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.
|
|
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
|
|
|
@@ -36,13 +36,14 @@ Before building the scene, `createScene` makes sure A-Frame 1.8.0 is on the page
|
|
|
36
36
|
|
|
37
37
|
`createScene` creates a root `#scene` node and, when a browser DOM exists, a `#tw-aframe-root > a-scene` host. The host is mounted inside the first detected TurboWarp stage wrapper or canvas parent, falling back to `document.body` only when no stage-like element is found.
|
|
38
38
|
|
|
39
|
-
The
|
|
39
|
+
The layer vocabulary is closed, and `turbowarp-ar` uses the same two values for its camera background:
|
|
40
40
|
|
|
41
41
|
- `above-stage`: A-Frame overlays the TurboWarp stage.
|
|
42
42
|
- `below-stage`: A-Frame stays behind the stage when the host CSS allows it.
|
|
43
|
-
- `camera-under-3d`: camera/video should sit below the 3D layer.
|
|
44
43
|
|
|
45
|
-
The
|
|
44
|
+
The block argument stays a plain string, so a project can pass anything; an unrecognized value falls back to `above-stage` instead of being stored as a layer the host cannot honor. On `above-stage` the host is given a stacking position one step above `turbowarp-ar`'s camera background, so a 3D scene renders over the camera image. `camera-under-3d` was listed here once and never implemented — the ordering it described is structural, not a value a caller can ask for.
|
|
45
|
+
|
|
46
|
+
The mode values, by contrast, are open strings that only describe intent:
|
|
46
47
|
|
|
47
48
|
- `3d`: ordinary embedded 3D scene.
|
|
48
49
|
- `camera`: camera-backed composition.
|
package/package.json
CHANGED
package/src/extension.ts
CHANGED
|
@@ -53,8 +53,28 @@ interface SceneEvent {
|
|
|
53
53
|
data: string;
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
+
/**
|
|
57
|
+
* Where the scene host sits relative to the TurboWarp stage.
|
|
58
|
+
*
|
|
59
|
+
* This is the whole vocabulary, and `turbowarp-ar` uses the same two values for its camera
|
|
60
|
+
* background. `mode` stays an open string because it only describes intent; `layer` decides where
|
|
61
|
+
* the host is drawn, so a value the host cannot honor does not belong in it.
|
|
62
|
+
*/
|
|
63
|
+
type SceneLayer = 'above-stage' | 'below-stage';
|
|
64
|
+
|
|
65
|
+
const SCENE_LAYERS: readonly SceneLayer[] = Object.freeze(['above-stage', 'below-stage']);
|
|
66
|
+
const DEFAULT_SCENE_LAYER: SceneLayer = 'above-stage';
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Stacking positions for the two hosts that can share the stage.
|
|
70
|
+
*
|
|
71
|
+
* `turbowarp-ar` puts its camera background one step below the `above-stage` value here, so a 3D
|
|
72
|
+
* scene renders over the camera image. Keep the two in step when either extension changes.
|
|
73
|
+
*/
|
|
74
|
+
const SCENE_HOST_Z_INDEX: Record<SceneLayer, string> = {'above-stage': '10', 'below-stage': '0'};
|
|
75
|
+
|
|
56
76
|
interface SceneOptions {
|
|
57
|
-
layer:
|
|
77
|
+
layer: SceneLayer;
|
|
58
78
|
mode: string;
|
|
59
79
|
}
|
|
60
80
|
|
|
@@ -139,7 +159,7 @@ export class TurboWarpAFrameExtension implements TurboWarpExtension {
|
|
|
139
159
|
private readonly eventQueue: SceneEvent[] = [];
|
|
140
160
|
private readonly domEventTypes = new Set<string>(DOM_EVENT_TYPES);
|
|
141
161
|
private readonly runtimeId = `twaframe-${Math.random().toString(36).slice(2)}`;
|
|
142
|
-
private sceneOptions: SceneOptions = {layer:
|
|
162
|
+
private sceneOptions: SceneOptions = {layer: DEFAULT_SCENE_LAYER, mode: '3d'};
|
|
143
163
|
private rootElement: Element | null = null;
|
|
144
164
|
private sceneReadyPending = false;
|
|
145
165
|
private lastEvent: SceneEvent | null = null;
|
|
@@ -158,6 +178,10 @@ export class TurboWarpAFrameExtension implements TurboWarpExtension {
|
|
|
158
178
|
this.setPosition({SELECTOR: selector, X: x, Y: y, Z: z}),
|
|
159
179
|
setRotation: (selector, x, y, z) =>
|
|
160
180
|
this.setRotation({SELECTOR: selector, X: x, Y: y, Z: z}),
|
|
181
|
+
setAttribute: (selector, name, value) =>
|
|
182
|
+
this.setAttribute({SELECTOR: selector, NAME: name, VALUE: value}),
|
|
183
|
+
setData: (selector, key, value) =>
|
|
184
|
+
this.setData({SELECTOR: selector, KEY: key, VALUE: value}),
|
|
161
185
|
emitEvent: (type, selector, data) =>
|
|
162
186
|
this.emitEvent({TYPE: type, SELECTOR: selector, DATA: data}),
|
|
163
187
|
deleteSelector: (selector) => this.deleteSelector({SELECTOR: selector}),
|
|
@@ -190,7 +214,7 @@ export class TurboWarpAFrameExtension implements TurboWarpExtension {
|
|
|
190
214
|
public async createScene(args: {LAYER: unknown; MODE: unknown}): Promise<void> {
|
|
191
215
|
await ensureAFrame();
|
|
192
216
|
this.sceneOptions = {
|
|
193
|
-
layer: Scratch.Cast.toString(args.LAYER)
|
|
217
|
+
layer: this.normalizeLayer(Scratch.Cast.toString(args.LAYER)),
|
|
194
218
|
mode: Scratch.Cast.toString(args.MODE) || '3d'
|
|
195
219
|
};
|
|
196
220
|
this.resetGraph();
|
|
@@ -761,7 +785,7 @@ export class TurboWarpAFrameExtension implements TurboWarpExtension {
|
|
|
761
785
|
host.style.position = 'absolute';
|
|
762
786
|
host.style.inset = '0';
|
|
763
787
|
host.style.pointerEvents = 'auto';
|
|
764
|
-
host.style.zIndex = this.sceneOptions.layer
|
|
788
|
+
host.style.zIndex = SCENE_HOST_Z_INDEX[this.sceneOptions.layer];
|
|
765
789
|
|
|
766
790
|
const scene = document.createElement('a-scene');
|
|
767
791
|
host.append(scene);
|
|
@@ -1297,6 +1321,15 @@ export class TurboWarpAFrameExtension implements TurboWarpExtension {
|
|
|
1297
1321
|
return this.normalizeToken(value) || 'node';
|
|
1298
1322
|
}
|
|
1299
1323
|
|
|
1324
|
+
/**
|
|
1325
|
+
* Blocks take whatever string a project hands them, so an unknown layer falls back to the default
|
|
1326
|
+
* rather than stopping the script, and never reaches the host as a value it cannot honor.
|
|
1327
|
+
*/
|
|
1328
|
+
private normalizeLayer(value: string): SceneLayer {
|
|
1329
|
+
const layer = value.trim() as SceneLayer;
|
|
1330
|
+
return SCENE_LAYERS.includes(layer) ? layer : DEFAULT_SCENE_LAYER;
|
|
1331
|
+
}
|
|
1332
|
+
|
|
1300
1333
|
private normalizeToken(value: string): string {
|
|
1301
1334
|
return value.trim().replace(/[^a-zA-Z0-9_-]/g, '-');
|
|
1302
1335
|
}
|
|
@@ -7,6 +7,10 @@ export interface AFrameScenePort {
|
|
|
7
7
|
createFromTemplate(template: string, instance: string, parent: string): void;
|
|
8
8
|
setPosition(selector: string, x: number, y: number, z: number): void;
|
|
9
9
|
setRotation(selector: string, x: number, y: number, z: number): void;
|
|
10
|
+
/** Sets an A-Frame component attribute, such as `visible`, on every matching node. */
|
|
11
|
+
setAttribute(selector: string, name: string, value: string): void;
|
|
12
|
+
/** Sets a `data-<key>` attribute on every matching node. */
|
|
13
|
+
setData(selector: string, key: string, value: string): void;
|
|
10
14
|
emitEvent(type: string, selector: string, data: string): void;
|
|
11
15
|
deleteSelector(selector: string): void;
|
|
12
16
|
countSelector(selector: string): number;
|
|
@@ -57,6 +61,14 @@ export function createRuntimeCapability(
|
|
|
57
61
|
assertActive();
|
|
58
62
|
scene.setRotation(selector, x, y, z);
|
|
59
63
|
},
|
|
64
|
+
setAttribute(selector, name, value) {
|
|
65
|
+
assertActive();
|
|
66
|
+
scene.setAttribute(selector, name, value);
|
|
67
|
+
},
|
|
68
|
+
setData(selector, key, value) {
|
|
69
|
+
assertActive();
|
|
70
|
+
scene.setData(selector, key, value);
|
|
71
|
+
},
|
|
60
72
|
emitEvent(type, selector, data) {
|
|
61
73
|
assertActive();
|
|
62
74
|
scene.emitEvent(type, selector, data);
|