@kubohiroya/turbowarp-camera-source 0.8.0 → 0.9.1

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
@@ -26,13 +26,13 @@ TurboWarp-Camera-Sourceは、MediaDevicesのカメラストリームを名前付
26
26
  次のURLをunsandboxed custom extensionとして読み込みます。
27
27
 
28
28
  ```text
29
- https://cdn.jsdelivr.net/npm/@kubohiroya/turbowarp-camera-source@0.8.0/dist/camera-source.js
29
+ https://cdn.jsdelivr.net/npm/@kubohiroya/turbowarp-camera-source@0.9.1/dist/camera-source.js
30
30
  ```
31
31
 
32
32
  npm hostでは次を使います。
33
33
 
34
34
  ```bash
35
- pnpm add @kubohiroya/turbowarp-camera-source@0.8.0
35
+ pnpm add @kubohiroya/turbowarp-camera-source@0.9.1
36
36
  ```
37
37
 
38
38
  ## Quick start
@@ -69,9 +69,6 @@ stop shared camera [pose]
69
69
  - `camera device count`: 更新済みカメラデバイス数を返します。
70
70
  - `camera device ID at [INDEX]`: 1始まりの位置でカメラdevice IDを返します。
71
71
  - `camera device label at [INDEX]`: 1始まりの位置でカメララベルを返します。
72
-
73
- 次の12ブロックは`calibrationProfilesV1`フラグがONのときだけパレットに出ます(既定OFF)。
74
-
75
72
  - `register camera profile [PROFILE_JSON]`: 内部校正プロファイルを検証して登録します。現行の`twcs/camera-intrinsics`と、旧`twrmc/camera-calibration`のどちらの文書も受け取ります。
76
73
  - `forget camera profile for [CAMERA_ID]`: 登録済みプロファイルを破棄します。
77
74
  - `camera [CAMERA_ID] is calibrated?`: プロファイルが登録されているかを返します。未登録は正常な状態です。
@@ -147,12 +144,6 @@ Scratchのtouchingまたはcolor sensing用の画像sourceとしては扱いま
147
144
 
148
145
  内部校正プロファイルの契約は本拡張が持つが、**プロファイルを作ることはしない**。チェスボード校正も、操作者が貼り付けたJSONも、将来の別方式も、検証を通る文書の生産者というだけで、ここからは区別できない。
149
146
 
150
- この面は`config/feature-flags.ts`の起動時固定フラグで囲ってあり、**既定はOFF**。カメラ取得とpreviewはどちらでも変わらない。
151
-
152
- ```js
153
- globalThis.__TWCS_FEATURE_FLAGS__ = {calibrationProfilesV1: true};
154
- ```
155
-
156
147
  **プロファイルはカメラの投影の仕方を述べるもので、どこに立っているかは述べない。** 共通world座標での姿勢は配置を解く拡張の責務で、両者を1つの文書に混ぜたことが、従来の`twrmc/camera-calibration`形式を出自のアプリ以外で使えなくしていた。旧文書は読めるが、その姿勢は配置として再公開せずに捨てる。
157
148
 
158
149
  **プロファイルを自分でスケールせず、内部行列を要求すること。** 校正時と違う解像度で届く場合、必要な計算は何が起きたかで変わる。単純な縮小なら`fx`・`fy`・`cx`・`cy`を比率倍するが、cropなら焦点距離はそのままで主点が平行移動する。trackの`resizeMode`を見られるのは本拡張だけなので、両者を区別できるのも本拡張だけ。**利用側がそれぞれ推測すれば、それぞれ違う推測をし、同じカメラがどの拡張から尋ねたかで違う幾何を返すことになる。** `camera intrinsics JSON`は現在のフレームに適合済みの数値を返し、cropやアスペクト変更で主点を置けない場合は空文字を返す。
package/README.md CHANGED
@@ -30,13 +30,13 @@ or select separate cameras for separate roles.
30
30
  Load this URL as an unsandboxed custom extension:
31
31
 
32
32
  ```text
33
- https://cdn.jsdelivr.net/npm/@kubohiroya/turbowarp-camera-source@0.8.0/dist/camera-source.js
33
+ https://cdn.jsdelivr.net/npm/@kubohiroya/turbowarp-camera-source@0.9.1/dist/camera-source.js
34
34
  ```
35
35
 
36
36
  For npm hosts:
37
37
 
38
38
  ```bash
39
- pnpm add @kubohiroya/turbowarp-camera-source@0.8.0
39
+ pnpm add @kubohiroya/turbowarp-camera-source@0.9.1
40
40
  ```
41
41
 
42
42
  ## Quick Start
@@ -393,13 +393,7 @@ noninteractive; it is intended for display, not Scratch touching or color-sensin
393
393
 
394
394
  This extension owns the contract for intrinsic calibration profiles but never produces one. Chessboard calibration, an operator pasting JSON, and any future calibrator are all just producers of a document that passes validation, and nothing here can tell them apart.
395
395
 
396
- The surface is behind a startup-fixed flag in `config/feature-flags.ts`, **off by default**. Camera acquisition and preview are untouched by it either way:
397
-
398
- ```js
399
- globalThis.__TWCS_FEATURE_FLAGS__ = {calibrationProfilesV1: true};
400
- ```
401
-
402
- A versioned capability is published for other extensions:
396
+ A versioned capability is published for other extensions, always:
403
397
 
404
398
  ```js
405
399
  const calibration = Scratch.vm.runtime.kubohiroyaCameraSourceCapability.requireVersion(1);
@@ -17,10 +17,6 @@
17
17
  license: "MPL-2.0",
18
18
  unsandboxed: true
19
19
  };
20
- //#endregion
21
- //#region config/feature-flags.ts
22
- var overrides = globalThis.__TWCS_FEATURE_FLAGS__;
23
- var featureFlags = Object.freeze({ calibrationProfilesV1: overrides?.calibrationProfilesV1 === true });
24
20
  var block_definitions_default = {
25
21
  extensionName: "Camera Source",
26
22
  blocks: [
@@ -168,7 +164,6 @@
168
164
  },
169
165
  {
170
166
  "opcode": "registerCameraProfile",
171
- "feature": "calibrationProfilesV1",
172
167
  "blockType": "COMMAND",
173
168
  "text": "register camera profile [PROFILE_JSON]",
174
169
  "arguments": { "PROFILE_JSON": {
@@ -178,7 +173,6 @@
178
173
  },
179
174
  {
180
175
  "opcode": "forgetCameraProfile",
181
- "feature": "calibrationProfilesV1",
182
176
  "blockType": "COMMAND",
183
177
  "text": "forget camera profile for [CAMERA_ID]",
184
178
  "arguments": { "CAMERA_ID": {
@@ -188,7 +182,6 @@
188
182
  },
189
183
  {
190
184
  "opcode": "cameraProfileRegistered",
191
- "feature": "calibrationProfilesV1",
192
185
  "blockType": "BOOLEAN",
193
186
  "text": "camera [CAMERA_ID] is calibrated?",
194
187
  "arguments": { "CAMERA_ID": {
@@ -198,7 +191,6 @@
198
191
  },
199
192
  {
200
193
  "opcode": "cameraProfileJson",
201
- "feature": "calibrationProfilesV1",
202
194
  "blockType": "REPORTER",
203
195
  "text": "camera profile JSON for [CAMERA_ID]",
204
196
  "arguments": { "CAMERA_ID": {
@@ -208,21 +200,18 @@
208
200
  },
209
201
  {
210
202
  "opcode": "cameraProfileError",
211
- "feature": "calibrationProfilesV1",
212
203
  "blockType": "REPORTER",
213
204
  "text": "camera profile error",
214
205
  "arguments": {}
215
206
  },
216
207
  {
217
208
  "opcode": "cameraProfileErrorDetail",
218
- "feature": "calibrationProfilesV1",
219
209
  "blockType": "REPORTER",
220
210
  "text": "camera profile error detail",
221
211
  "arguments": {}
222
212
  },
223
213
  {
224
214
  "opcode": "cameraProfileCompatibility",
225
- "feature": "calibrationProfilesV1",
226
215
  "blockType": "REPORTER",
227
216
  "text": "camera profile compatibility for [CAMERA_ID]",
228
217
  "arguments": { "CAMERA_ID": {
@@ -232,7 +221,6 @@
232
221
  },
233
222
  {
234
223
  "opcode": "cameraProfileCompatibilityDetail",
235
- "feature": "calibrationProfilesV1",
236
224
  "blockType": "REPORTER",
237
225
  "text": "camera profile compatibility detail for [CAMERA_ID]",
238
226
  "arguments": { "CAMERA_ID": {
@@ -242,7 +230,6 @@
242
230
  },
243
231
  {
244
232
  "opcode": "cameraProfileAdaptation",
245
- "feature": "calibrationProfilesV1",
246
233
  "blockType": "REPORTER",
247
234
  "text": "camera profile adaptation for [CAMERA_ID]",
248
235
  "arguments": { "CAMERA_ID": {
@@ -252,7 +239,6 @@
252
239
  },
253
240
  {
254
241
  "opcode": "cameraProfileIntrinsicsJson",
255
- "feature": "calibrationProfilesV1",
256
242
  "blockType": "REPORTER",
257
243
  "text": "camera intrinsics JSON for [CAMERA_ID]",
258
244
  "arguments": { "CAMERA_ID": {
@@ -262,7 +248,6 @@
262
248
  },
263
249
  {
264
250
  "opcode": "cameraConditionsJson",
265
- "feature": "calibrationProfilesV1",
266
251
  "blockType": "REPORTER",
267
252
  "text": "camera conditions JSON for [CAMERA_ID]",
268
253
  "arguments": { "CAMERA_ID": {
@@ -272,7 +257,6 @@
272
257
  },
273
258
  {
274
259
  "opcode": "cameraConditionsGeneration",
275
- "feature": "calibrationProfilesV1",
276
260
  "blockType": "REPORTER",
277
261
  "text": "camera conditions generation for [CAMERA_ID]",
278
262
  "arguments": { "CAMERA_ID": {
@@ -1119,16 +1103,12 @@
1119
1103
  this.lastCurrentTime = NaN;
1120
1104
  this.handleVideoFrame = () => {
1121
1105
  if (this.disposed) return;
1122
- this.dirty = true;
1123
- this.onFrame(this.syncMetrics());
1106
+ this.markChanged();
1124
1107
  this.scheduleFrame();
1125
1108
  };
1126
1109
  this.handleAnimationFrame = () => {
1127
1110
  if (this.disposed) return;
1128
- if (this.video.currentTime !== this.lastCurrentTime) {
1129
- this.dirty = true;
1130
- this.onFrame(this.syncMetrics());
1131
- }
1111
+ if (this.video.currentTime !== this.lastCurrentTime) this.markChanged();
1132
1112
  this.scheduleFrame();
1133
1113
  };
1134
1114
  this.video = video;
@@ -1185,6 +1165,31 @@
1185
1165
  this.rotationCenter[1] = height / 2;
1186
1166
  return true;
1187
1167
  }
1168
+ /**
1169
+ * Says a new frame arrived, to everything that has to hear it.
1170
+ *
1171
+ * Three separate listeners, and missing any one of them stops the picture
1172
+ * without stopping anything else:
1173
+ *
1174
+ * `dirty` is this skin's own note that the texture it holds is behind the
1175
+ * video. `getTexture` reads it.
1176
+ *
1177
+ * `emitWasAltered` is the renderer's. A renderer that redrew every frame
1178
+ * regardless would not need it, but this one skips the work when nothing
1179
+ * says it changed -- and a video is the one skin whose content changes
1180
+ * without anybody touching a drawable. Without this the preview updated
1181
+ * only when something else forced a redraw, so resizing the stage showed
1182
+ * the current frame and then it froze again. `draw` was still being called
1183
+ * thirty times a second; it was returning immediately every time.
1184
+ *
1185
+ * `onFrame` is the extension's, which asks the VM for a redraw and keeps
1186
+ * the drawable's size in step with the video's.
1187
+ */
1188
+ markChanged() {
1189
+ this.dirty = true;
1190
+ this.emitWasAltered();
1191
+ this.onFrame(this.syncMetrics());
1192
+ }
1188
1193
  scheduleFrame() {
1189
1194
  if (typeof this.video.requestVideoFrameCallback === "function") this.videoFrameCallbackId = this.video.requestVideoFrameCallback(this.handleVideoFrame);
1190
1195
  else if (typeof globalThis.requestAnimationFrame === "function") this.animationFrameId = globalThis.requestAnimationFrame(this.handleAnimationFrame);
@@ -1332,7 +1337,6 @@
1332
1337
  this.generations = /* @__PURE__ */ new Map();
1333
1338
  this.lastConditions = /* @__PURE__ */ new Map();
1334
1339
  this.assessments = /* @__PURE__ */ new Map();
1335
- this.calibrationEnabled = featureFlags.calibrationProfilesV1;
1336
1340
  this.devices = [];
1337
1341
  this.dispose = () => {
1338
1342
  this.stopAllCameras();
@@ -1347,7 +1351,7 @@
1347
1351
  this.profileError = void 0;
1348
1352
  };
1349
1353
  Scratch.vm.runtime[cameraSourceRuntimeKey] = this;
1350
- this.capability = this.calibrationEnabled ? createRuntimeCapability({
1354
+ this.capability = createRuntimeCapability({
1351
1355
  registerProfile: (document) => this.profiles.register(document),
1352
1356
  forgetProfile: (cameraId) => this.profiles.forget(cameraId),
1353
1357
  profileFor: (cameraId) => this.profiles.get(cameraId),
@@ -1358,8 +1362,8 @@
1358
1362
  intrinsicsFor: (cameraId) => this.intrinsicsOf(cameraId),
1359
1363
  conditionsFor: (cameraId) => this.conditionsOf(cameraId),
1360
1364
  conditionsGeneration: (cameraId) => this.generationOf(cameraId)
1361
- }) : void 0;
1362
- if (this.capability) Scratch.vm.runtime[cameraSourceCapabilityKey] = this.capability;
1365
+ });
1366
+ Scratch.vm.runtime[cameraSourceCapabilityKey] = this.capability;
1363
1367
  Scratch.vm.runtime.on?.("PROJECT_STOP_ALL", this.handleProjectBoundary);
1364
1368
  Scratch.vm.runtime.on?.("PROJECT_LOADED", this.handleProjectBoundary);
1365
1369
  Scratch.vm.runtime.on?.("RUNTIME_DISPOSED", this.dispose);
@@ -1368,7 +1372,7 @@
1368
1372
  return {
1369
1373
  id: extensionConfig.id,
1370
1374
  name: Scratch.translate(block_definitions_default.extensionName),
1371
- blocks: blockDefinitions.filter((block) => block.feature === void 0 || this.calibrationEnabled).map((block) => this.toScratchBlock(block)),
1375
+ blocks: blockDefinitions.map((block) => this.toScratchBlock(block)),
1372
1376
  menus: Object.fromEntries(Object.entries(menuDefinitions).map(([id, menu]) => [id, {
1373
1377
  acceptReporters: menu.acceptReporters,
1374
1378
  items: [...menu.items]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubohiroya/turbowarp-camera-source",
3
- "version": "0.8.0",
3
+ "version": "0.9.1",
4
4
  "author": "Hiroya Kubo <hiroya@cuc.ac.jp>",
5
5
  "description": "A TurboWarp capability extension for sharing one MediaDevices camera stream across extensions.",
6
6
  "type": "module",