@threenative/playtest 0.3.0 → 0.3.2
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/dist/{diagnostics-D89qJhf0.d.ts → diagnostics-f8464bJw.d.ts} +279 -14
- package/dist/index.d.ts +5 -5
- package/dist/index.js +2483 -440
- package/dist/protocol.d.ts +270 -2
- package/dist/runner/cli.d.ts +15 -3
- package/dist/runner/cli.js +8311 -2466
- package/dist/runner/index.d.ts +211 -7
- package/dist/runner/index.js +4847 -753
- package/dist/{shared-Ax3-pneQ.d.ts → shared-BGwYk5HG.d.ts} +20 -1
- package/dist/three/index.d.ts +27 -3
- package/dist/three/index.js +358 -7
- package/package.json +20 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IPlaytestObservationSnapshot } from './protocol.js';
|
|
2
|
-
import { c as IPlaytestReport, w as IPlaytestProtocolDiagnostic, p as IPlaytestDiagnosticsPolicy, d as IPlaytestAssertionResult } from './diagnostics-
|
|
2
|
+
import { c as IPlaytestReport, w as IPlaytestProtocolDiagnostic, p as IPlaytestDiagnosticsPolicy, d as IPlaytestAssertionResult } from './diagnostics-f8464bJw.js';
|
|
3
3
|
|
|
4
4
|
interface IPlaytestServerConfig {
|
|
5
5
|
command: string;
|
|
@@ -18,6 +18,7 @@ interface IStandalonePlaytestConfig {
|
|
|
18
18
|
android?: {
|
|
19
19
|
activity: string;
|
|
20
20
|
packageName: string;
|
|
21
|
+
user?: string;
|
|
21
22
|
};
|
|
22
23
|
adbPath?: string;
|
|
23
24
|
/** @see IAndroidDriverOptions.touchRotation */
|
|
@@ -33,6 +34,7 @@ interface IStandalonePlaytestConfig {
|
|
|
33
34
|
device?: string;
|
|
34
35
|
desktop?: {
|
|
35
36
|
executable: string;
|
|
37
|
+
hostArgs?: readonly string[];
|
|
36
38
|
};
|
|
37
39
|
endpoint?: string;
|
|
38
40
|
headless: boolean;
|
|
@@ -81,6 +83,11 @@ declare const PLAYTEST_FLAGS: {
|
|
|
81
83
|
readonly summary: "Android launch activity";
|
|
82
84
|
readonly takesValue: true;
|
|
83
85
|
};
|
|
86
|
+
readonly "--user": {
|
|
87
|
+
readonly default: "current foreground Android user";
|
|
88
|
+
readonly summary: "Android user id for force-stop and launch";
|
|
89
|
+
readonly takesValue: true;
|
|
90
|
+
};
|
|
84
91
|
readonly "--app": {
|
|
85
92
|
readonly default: "required for iOS";
|
|
86
93
|
readonly summary: "built iOS .app bundle";
|
|
@@ -133,6 +140,12 @@ declare const PLAYTEST_FLAGS: {
|
|
|
133
140
|
readonly summary: "show the browser window";
|
|
134
141
|
readonly takesValue: false;
|
|
135
142
|
};
|
|
143
|
+
readonly "--host-arg": {
|
|
144
|
+
readonly default: "none";
|
|
145
|
+
readonly repeatable: true;
|
|
146
|
+
readonly summary: "argument passed to the native desktop host, repeatable";
|
|
147
|
+
readonly takesValue: true;
|
|
148
|
+
};
|
|
136
149
|
readonly "--mailbox-root": {
|
|
137
150
|
readonly default: "Android external files directory";
|
|
138
151
|
readonly summary: "native device mailbox directory";
|
|
@@ -241,6 +254,12 @@ interface IStandalonePlaytestReport extends IPlaytestReport {
|
|
|
241
254
|
phase: string;
|
|
242
255
|
progress: number;
|
|
243
256
|
rule: string;
|
|
257
|
+
timeline?: {
|
|
258
|
+
loadStartedMs?: number;
|
|
259
|
+
enteredMs?: number;
|
|
260
|
+
compileSettledMs?: number;
|
|
261
|
+
readyMs?: number;
|
|
262
|
+
};
|
|
244
263
|
};
|
|
245
264
|
debugColliders?: boolean;
|
|
246
265
|
input?: string;
|
package/dist/three/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Camera, Scene, Object3D, Vector2 } from 'three';
|
|
2
|
-
import { IPlaytestSampleRequest, IPlaytestObservationSnapshot, IPlaytestBridgeV1, JsonValue, IPlaytestGameplayObservation, IPlaytestRuntimeDiagnosticsSample, IPlaytestRenderChainObservation, IPlaytestStartupObservation } from '../protocol.js';
|
|
2
|
+
import { IPlaytestSampleRequest, IPlaytestObservationSnapshot, IPlaytestBridgeV1, JsonValue, IPlaytestGameplayObservation, IPlaytestRuntimeDiagnosticsSample, IPlaytestRenderChainObservation, IPlaytestStartupObservation, IPlaytestSceneObservation } from '../protocol.js';
|
|
3
3
|
|
|
4
4
|
type RenderAdvisorOwner = "framework" | "generated-src";
|
|
5
5
|
type RenderAdvisorSeverity = "info" | "warning";
|
|
@@ -163,7 +163,7 @@ interface IThreePlaytestBridgeOptions {
|
|
|
163
163
|
entities?: readonly IThreePlaytestEntity[] | (() => readonly IThreePlaytestEntity[]);
|
|
164
164
|
fixedStep?: (ticks: number) => Promise<number | void> | number | void;
|
|
165
165
|
gameplay?: () => IPlaytestGameplayObservation;
|
|
166
|
-
gameplayChannels?: () => readonly ("runtime.contacts" | "runtime.tags" | "runtime.world")[];
|
|
166
|
+
gameplayChannels?: () => readonly ("runtime.contacts" | "runtime.tags" | "runtime.transitions" | "runtime.world")[];
|
|
167
167
|
runtimeDiagnosticsSeries?: () => readonly IPlaytestRuntimeDiagnosticsSample[];
|
|
168
168
|
events?: () => JsonValue[];
|
|
169
169
|
/** Physics bodies to retain per labelled step. Requires the authoritative tick provider. */
|
|
@@ -190,4 +190,28 @@ interface IDeviceBridgeInstallation {
|
|
|
190
190
|
declare function connectDevicePlaytestBridge(bridge: IPlaytestBridgeV1, endpoint: string): IDeviceBridgeInstallation;
|
|
191
191
|
declare function readPlaytestEndpoint(): string | undefined;
|
|
192
192
|
|
|
193
|
-
|
|
193
|
+
/**
|
|
194
|
+
* The room the game is played in, read off the scene graph.
|
|
195
|
+
*
|
|
196
|
+
* `doctor --url` listed lights, materials and camera framing under "not observed", so an agent
|
|
197
|
+
* looking at a black or washed-out frame had nothing to read and went to screenshots — the one
|
|
198
|
+
* instrument that cannot say *why*. Everything here is a count or a name taken from the objects
|
|
199
|
+
* the renderer will use. It decides nothing about how the game looks.
|
|
200
|
+
*/
|
|
201
|
+
/**
|
|
202
|
+
* Ceilings on the walk. A scene past either is described as far as the cap and says so; a count
|
|
203
|
+
* silently capped would be read as a total, and a total nobody measured is exactly the confident
|
|
204
|
+
* empty number this harness exists to prevent.
|
|
205
|
+
*/
|
|
206
|
+
declare const SCENE_WALK_OBJECT_CAP = 20000;
|
|
207
|
+
declare const SCENE_LIGHT_CAP = 64;
|
|
208
|
+
/**
|
|
209
|
+
* Walk the scene once and report what is mounted in it.
|
|
210
|
+
* @situation ask what lights, materials and framing a running game actually has
|
|
211
|
+
* @constraint reports counts and names only; nothing here decides how the game looks
|
|
212
|
+
* @constraint a walk that hits {@link SCENE_WALK_OBJECT_CAP} reports `truncated: true`
|
|
213
|
+
* @example const room = observeSceneResources(ctx.scene, ctx.camera);
|
|
214
|
+
*/
|
|
215
|
+
declare function observeSceneResources(scene: Scene, camera: Camera): IPlaytestSceneObservation;
|
|
216
|
+
|
|
217
|
+
export { type IDeviceBridgeInstallation, type IRenderAdvisorExamplePaths, type IRenderAdvisorInput, type IRenderAdvisorObservedInput, type IRenderAdvisorObservedPass, type IRenderAdvisorRecommendation, type IRenderAdvisorReport, type IThreePlaytestBridgeInstallation, type IThreePlaytestBridgeOptions, type IThreePlaytestEntity, type IThreePlaytestPhysics, type IThreePlaytestPhysicsBody, type IThreePlaytestResources, PLAYTEST_PHYSICS_BODY_LIMIT, PLAYTEST_PHYSICS_SAMPLE_LIMIT, SCENE_LIGHT_CAP, SCENE_WALK_OBJECT_CAP, ThreePlaytestPhysicsRecorder, adviseThreeRenderWorkload, connectDevicePlaytestBridge, installThreePlaytestBridge, observeSceneResources, readPlaytestEndpoint };
|
package/dist/three/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
2
|
+
import { Box3, Vector3, Vector2, Matrix4, Frustum } from 'three';
|
|
3
3
|
|
|
4
4
|
// src/three/renderWorkloadAdvisor.ts
|
|
5
5
|
var DEFAULT_TOP_N = 10;
|
|
@@ -479,6 +479,341 @@ function objectPath(object) {
|
|
|
479
479
|
}
|
|
480
480
|
return parts.join("/");
|
|
481
481
|
}
|
|
482
|
+
var SCENE_NODE_WALK_CAP = 5e4;
|
|
483
|
+
var SCENE_NODE_DEFAULT_LIMIT = 50;
|
|
484
|
+
var SCENE_NODE_MAX_LIMIT = 500;
|
|
485
|
+
var SCENE_NODE_MAX_SELECTORS = 16;
|
|
486
|
+
var LIT_MATERIAL_PATTERN = /standard|physical|lambert|phong|toon/iu;
|
|
487
|
+
var MATERIAL_MAP_SLOTS = [
|
|
488
|
+
"alphaMap",
|
|
489
|
+
"anisotropyMap",
|
|
490
|
+
"aoMap",
|
|
491
|
+
"bumpMap",
|
|
492
|
+
"clearcoatMap",
|
|
493
|
+
"displacementMap",
|
|
494
|
+
"emissiveMap",
|
|
495
|
+
"envMap",
|
|
496
|
+
"iridescenceMap",
|
|
497
|
+
"lightMap",
|
|
498
|
+
"map",
|
|
499
|
+
"metalnessMap",
|
|
500
|
+
"normalMap",
|
|
501
|
+
"roughnessMap",
|
|
502
|
+
"sheenColorMap",
|
|
503
|
+
"specularMap",
|
|
504
|
+
"transmissionMap"
|
|
505
|
+
];
|
|
506
|
+
function isColorLike(value) {
|
|
507
|
+
return typeof value === "object" && value !== null && value.isColor === true && typeof value.getHexString === "function";
|
|
508
|
+
}
|
|
509
|
+
function hexOf(value) {
|
|
510
|
+
return isColorLike(value) ? `#${value.getHexString()}` : void 0;
|
|
511
|
+
}
|
|
512
|
+
function finite(value) {
|
|
513
|
+
return typeof value === "number" && Number.isFinite(value) ? value : void 0;
|
|
514
|
+
}
|
|
515
|
+
function typeNameOf(value) {
|
|
516
|
+
const declared = value.type;
|
|
517
|
+
if (typeof declared === "string" && declared.length > 0) return declared;
|
|
518
|
+
return value.constructor.name;
|
|
519
|
+
}
|
|
520
|
+
function sceneNodePath(object) {
|
|
521
|
+
const parts = [];
|
|
522
|
+
let current = object;
|
|
523
|
+
while (current !== null) {
|
|
524
|
+
const anonymous = current.parent === null ? typeNameOf(current) : `${typeNameOf(current)}[${current.uuid.slice(0, 8)}]`;
|
|
525
|
+
parts.unshift(current.name || anonymous);
|
|
526
|
+
current = current.parent;
|
|
527
|
+
}
|
|
528
|
+
return parts.join("/");
|
|
529
|
+
}
|
|
530
|
+
function visibleInTree(object) {
|
|
531
|
+
let current = object;
|
|
532
|
+
while (current !== null) {
|
|
533
|
+
if (!current.visible) return false;
|
|
534
|
+
current = current.parent;
|
|
535
|
+
}
|
|
536
|
+
return true;
|
|
537
|
+
}
|
|
538
|
+
function textureLoaded(value) {
|
|
539
|
+
if (typeof value !== "object" || value === null) return false;
|
|
540
|
+
const image = value.image;
|
|
541
|
+
if (image === null || image === void 0) {
|
|
542
|
+
const mipmaps = value.mipmaps;
|
|
543
|
+
return Array.isArray(mipmaps) && mipmaps.length > 0;
|
|
544
|
+
}
|
|
545
|
+
if (typeof image !== "object") return true;
|
|
546
|
+
const width = finite(image.width);
|
|
547
|
+
const height = finite(image.height);
|
|
548
|
+
if (width === void 0 || height === void 0) return true;
|
|
549
|
+
return width > 0 && height > 0;
|
|
550
|
+
}
|
|
551
|
+
function materialObservation(value) {
|
|
552
|
+
const material = value;
|
|
553
|
+
const type = typeNameOf(value);
|
|
554
|
+
const maps = [];
|
|
555
|
+
const mapsUnloaded = [];
|
|
556
|
+
for (const slot of MATERIAL_MAP_SLOTS) {
|
|
557
|
+
const texture = material[slot];
|
|
558
|
+
if (typeof texture !== "object" || texture === null) continue;
|
|
559
|
+
maps.push(slot);
|
|
560
|
+
if (!textureLoaded(texture)) mapsUnloaded.push(slot);
|
|
561
|
+
}
|
|
562
|
+
const color = hexOf(material.color);
|
|
563
|
+
const emissive = hexOf(material.emissive);
|
|
564
|
+
const metalness = finite(material.metalness);
|
|
565
|
+
const opacity = finite(material.opacity);
|
|
566
|
+
const roughness = finite(material.roughness);
|
|
567
|
+
const name = material.name;
|
|
568
|
+
return {
|
|
569
|
+
...color === void 0 ? {} : { color },
|
|
570
|
+
...emissive === void 0 ? {} : { emissive },
|
|
571
|
+
lit: LIT_MATERIAL_PATTERN.test(type),
|
|
572
|
+
maps,
|
|
573
|
+
mapsUnloaded,
|
|
574
|
+
...metalness === void 0 ? {} : { metalness },
|
|
575
|
+
name: typeof name === "string" ? name : "",
|
|
576
|
+
...opacity === void 0 ? {} : { opacity },
|
|
577
|
+
...roughness === void 0 ? {} : { roughness },
|
|
578
|
+
transparent: material.transparent === true,
|
|
579
|
+
type,
|
|
580
|
+
visible: material.visible !== false
|
|
581
|
+
};
|
|
582
|
+
}
|
|
583
|
+
function materialsOf(object) {
|
|
584
|
+
const material = object.material;
|
|
585
|
+
if (material === void 0 || material === null) return void 0;
|
|
586
|
+
const entries = Array.isArray(material) ? material : [material];
|
|
587
|
+
const observed = entries.filter((entry) => typeof entry === "object" && entry !== null);
|
|
588
|
+
return observed.length === 0 ? void 0 : observed.map(materialObservation);
|
|
589
|
+
}
|
|
590
|
+
function geometryOf(object) {
|
|
591
|
+
const geometry = object.geometry;
|
|
592
|
+
if (typeof geometry !== "object" || geometry === null) return void 0;
|
|
593
|
+
const attributes = geometry.attributes;
|
|
594
|
+
const names = typeof attributes === "object" && attributes !== null ? Object.keys(attributes).sort() : [];
|
|
595
|
+
const position = geometry.attributes?.position;
|
|
596
|
+
const vertices = finite(position?.count) ?? 0;
|
|
597
|
+
const index = geometry.index;
|
|
598
|
+
const indexCount = finite(index?.count);
|
|
599
|
+
const triangles = Math.floor((indexCount ?? vertices) / 3);
|
|
600
|
+
return { attributes: names, triangles, vertices };
|
|
601
|
+
}
|
|
602
|
+
function animationOf(object) {
|
|
603
|
+
const animations = object.animations;
|
|
604
|
+
if (!Array.isArray(animations) || animations.length === 0) return void 0;
|
|
605
|
+
const clips = [];
|
|
606
|
+
for (const clip of animations) {
|
|
607
|
+
if (typeof clip !== "object" || clip === null) continue;
|
|
608
|
+
const name = clip.name;
|
|
609
|
+
clips.push(typeof name === "string" ? name : "");
|
|
610
|
+
}
|
|
611
|
+
return { clips, playing: [] };
|
|
612
|
+
}
|
|
613
|
+
function selectorMatches(object, path, selector) {
|
|
614
|
+
if (selector.name !== void 0 && object.name !== selector.name) return false;
|
|
615
|
+
if (selector.type !== void 0 && typeNameOf(object) !== selector.type) return false;
|
|
616
|
+
if (selector.nameContains !== void 0 && !object.name.toLowerCase().includes(selector.nameContains.toLowerCase()))
|
|
617
|
+
return false;
|
|
618
|
+
if (selector.pathContains !== void 0 && !path.toLowerCase().includes(selector.pathContains.toLowerCase()))
|
|
619
|
+
return false;
|
|
620
|
+
return true;
|
|
621
|
+
}
|
|
622
|
+
function nodeObservation(object, path, frustum) {
|
|
623
|
+
const position = object.getWorldPosition(new Vector3());
|
|
624
|
+
const scale = object.getWorldScale(new Vector3());
|
|
625
|
+
const box = new Box3().setFromObject(object);
|
|
626
|
+
const bounds = box.isEmpty() ? void 0 : {
|
|
627
|
+
max: [box.max.x, box.max.y, box.max.z],
|
|
628
|
+
min: [box.min.x, box.min.y, box.min.z]
|
|
629
|
+
};
|
|
630
|
+
const instances = finite(object.count);
|
|
631
|
+
const skeleton = object.skeleton;
|
|
632
|
+
const bones = Array.isArray(skeleton?.bones) ? skeleton.bones.length : void 0;
|
|
633
|
+
const materials = materialsOf(object);
|
|
634
|
+
const geometry = geometryOf(object);
|
|
635
|
+
const animation = animationOf(object);
|
|
636
|
+
return {
|
|
637
|
+
...animation === void 0 ? {} : { animation },
|
|
638
|
+
...bounds === void 0 ? {} : { bounds },
|
|
639
|
+
...geometry === void 0 ? {} : { geometry },
|
|
640
|
+
// Frustum membership is only reported when a camera projection was available to test it
|
|
641
|
+
// against; an untested node is absent, never `false`.
|
|
642
|
+
...frustum === void 0 || bounds === void 0 ? {} : { inFrustum: frustum.intersectsBox(box) },
|
|
643
|
+
...instances === void 0 ? {} : { instances },
|
|
644
|
+
...materials === void 0 ? {} : { materials },
|
|
645
|
+
name: object.name,
|
|
646
|
+
path,
|
|
647
|
+
position: [position.x, position.y, position.z],
|
|
648
|
+
scale: [scale.x, scale.y, scale.z],
|
|
649
|
+
...bones === void 0 ? {} : { skinned: { bones } },
|
|
650
|
+
type: typeNameOf(object),
|
|
651
|
+
visible: object.visible,
|
|
652
|
+
visibleInTree: visibleInTree(object)
|
|
653
|
+
};
|
|
654
|
+
}
|
|
655
|
+
function cameraFrustum(camera) {
|
|
656
|
+
const projection = camera.projectionMatrix;
|
|
657
|
+
const inverse = camera.matrixWorldInverse;
|
|
658
|
+
if (!(projection instanceof Matrix4) || !(inverse instanceof Matrix4)) return void 0;
|
|
659
|
+
camera.updateMatrixWorld();
|
|
660
|
+
return new Frustum().setFromProjectionMatrix(new Matrix4().multiplyMatrices(projection, inverse));
|
|
661
|
+
}
|
|
662
|
+
function resolveLimit(selector) {
|
|
663
|
+
const requested = selector.limit ?? SCENE_NODE_DEFAULT_LIMIT;
|
|
664
|
+
return Math.min(Math.max(requested, 0), SCENE_NODE_MAX_LIMIT);
|
|
665
|
+
}
|
|
666
|
+
function observeSceneNodes(scene, camera, selectors) {
|
|
667
|
+
if (selectors.length > SCENE_NODE_MAX_SELECTORS)
|
|
668
|
+
throw new Error(
|
|
669
|
+
`A playtest sample requested ${selectors.length} scene-node selectors; the protocol allows ${SCENE_NODE_MAX_SELECTORS}.`
|
|
670
|
+
);
|
|
671
|
+
const frustum = cameraFrustum(camera);
|
|
672
|
+
const results = selectors.map((selector) => ({
|
|
673
|
+
limit: resolveLimit(selector),
|
|
674
|
+
matched: 0,
|
|
675
|
+
nodes: [],
|
|
676
|
+
selector,
|
|
677
|
+
truncated: false
|
|
678
|
+
}));
|
|
679
|
+
let walked = 0;
|
|
680
|
+
let walkCapped = false;
|
|
681
|
+
scene.traverse((object) => {
|
|
682
|
+
walked += 1;
|
|
683
|
+
if (walked > SCENE_NODE_WALK_CAP) {
|
|
684
|
+
walkCapped = true;
|
|
685
|
+
return;
|
|
686
|
+
}
|
|
687
|
+
const path = sceneNodePath(object);
|
|
688
|
+
for (const result of results) {
|
|
689
|
+
if (!selectorMatches(object, path, result.selector)) continue;
|
|
690
|
+
result.matched += 1;
|
|
691
|
+
if (result.nodes.length < result.limit) result.nodes.push(nodeObservation(object, path, frustum));
|
|
692
|
+
else result.truncated = true;
|
|
693
|
+
}
|
|
694
|
+
});
|
|
695
|
+
return results.map(({ matched, nodes, selector, truncated }) => ({
|
|
696
|
+
matched,
|
|
697
|
+
nodes,
|
|
698
|
+
selector,
|
|
699
|
+
truncated: truncated || walkCapped
|
|
700
|
+
}));
|
|
701
|
+
}
|
|
702
|
+
var SCENE_WALK_OBJECT_CAP = 2e4;
|
|
703
|
+
var SCENE_LIGHT_CAP = 64;
|
|
704
|
+
function isColorLike2(value) {
|
|
705
|
+
return typeof value === "object" && value !== null && value.isColor === true && typeof value.getHexString === "function";
|
|
706
|
+
}
|
|
707
|
+
function hexOf2(value) {
|
|
708
|
+
return isColorLike2(value) ? `#${value.getHexString()}` : "unobserved";
|
|
709
|
+
}
|
|
710
|
+
function finite2(value) {
|
|
711
|
+
return typeof value === "number" && Number.isFinite(value) ? value : void 0;
|
|
712
|
+
}
|
|
713
|
+
function typeNameOf2(value) {
|
|
714
|
+
const declared = value.type;
|
|
715
|
+
if (typeof declared === "string" && declared.length > 0) return declared;
|
|
716
|
+
return value.constructor.name;
|
|
717
|
+
}
|
|
718
|
+
function backgroundOf(scene) {
|
|
719
|
+
const background = scene.background;
|
|
720
|
+
if (background === null || background === void 0) return "none";
|
|
721
|
+
if (isColorLike2(background)) return `color:${hexOf2(background)}`;
|
|
722
|
+
return typeof background === "object" ? typeNameOf2(background) : "unobserved";
|
|
723
|
+
}
|
|
724
|
+
function fogOf(scene) {
|
|
725
|
+
const fog = scene.fog;
|
|
726
|
+
if (typeof fog !== "object" || fog === null) return void 0;
|
|
727
|
+
const color = hexOf2(fog.color);
|
|
728
|
+
const density = fog.density;
|
|
729
|
+
if (typeof density === "number" && Number.isFinite(density))
|
|
730
|
+
return { color, density, type: "exponential" };
|
|
731
|
+
const near = fog.near;
|
|
732
|
+
const far = fog.far;
|
|
733
|
+
if (typeof near !== "number" || typeof far !== "number") return void 0;
|
|
734
|
+
if (!Number.isFinite(near) || !Number.isFinite(far)) return void 0;
|
|
735
|
+
return { color, far, near, type: "linear" };
|
|
736
|
+
}
|
|
737
|
+
function cameraObservation(camera) {
|
|
738
|
+
const position = camera.getWorldPosition(new Vector3());
|
|
739
|
+
const forward = camera.getWorldDirection(new Vector3());
|
|
740
|
+
const perspective = camera;
|
|
741
|
+
const near = finite2(perspective.near);
|
|
742
|
+
const far = finite2(perspective.far);
|
|
743
|
+
const fov = finite2(perspective.fov);
|
|
744
|
+
return {
|
|
745
|
+
...far === void 0 ? {} : { far },
|
|
746
|
+
forward: [forward.x, forward.y, forward.z],
|
|
747
|
+
...fov === void 0 ? {} : { fov },
|
|
748
|
+
...near === void 0 ? {} : { near },
|
|
749
|
+
position: [position.x, position.y, position.z],
|
|
750
|
+
type: typeNameOf2(camera)
|
|
751
|
+
};
|
|
752
|
+
}
|
|
753
|
+
function lightObservation(object) {
|
|
754
|
+
const light = object;
|
|
755
|
+
const intensity = finite2(light.intensity);
|
|
756
|
+
return {
|
|
757
|
+
color: hexOf2(light.color),
|
|
758
|
+
...intensity === void 0 ? {} : { intensity },
|
|
759
|
+
type: typeNameOf2(object),
|
|
760
|
+
visible: object.visible
|
|
761
|
+
};
|
|
762
|
+
}
|
|
763
|
+
function countMaterials(object, counted, counts) {
|
|
764
|
+
const material = object.material;
|
|
765
|
+
const entries = Array.isArray(material) ? material : [material];
|
|
766
|
+
for (const entry of entries) {
|
|
767
|
+
if (typeof entry !== "object" || entry === null) continue;
|
|
768
|
+
const uuid = entry.uuid;
|
|
769
|
+
const key = typeof uuid === "string" ? uuid : void 0;
|
|
770
|
+
if (key !== void 0) {
|
|
771
|
+
if (counted.has(key)) continue;
|
|
772
|
+
counted.add(key);
|
|
773
|
+
}
|
|
774
|
+
const name = typeNameOf2(entry);
|
|
775
|
+
counts[name] = (counts[name] ?? 0) + 1;
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
function observeSceneResources(scene, camera) {
|
|
779
|
+
const lights = [];
|
|
780
|
+
const materials = {};
|
|
781
|
+
const countedMaterials = /* @__PURE__ */ new Set();
|
|
782
|
+
let objects = 0;
|
|
783
|
+
let truncated = false;
|
|
784
|
+
scene.traverse((object) => {
|
|
785
|
+
objects += 1;
|
|
786
|
+
if (objects > SCENE_WALK_OBJECT_CAP) {
|
|
787
|
+
truncated = true;
|
|
788
|
+
return;
|
|
789
|
+
}
|
|
790
|
+
if (object.isLight === true) {
|
|
791
|
+
if (lights.length < SCENE_LIGHT_CAP) lights.push(lightObservation(object));
|
|
792
|
+
else truncated = true;
|
|
793
|
+
return;
|
|
794
|
+
}
|
|
795
|
+
countMaterials(object, countedMaterials, materials);
|
|
796
|
+
});
|
|
797
|
+
const bounds = new Box3().setFromObject(scene);
|
|
798
|
+
const fog = fogOf(scene);
|
|
799
|
+
return {
|
|
800
|
+
background: backgroundOf(scene),
|
|
801
|
+
camera: cameraObservation(camera),
|
|
802
|
+
...fog === void 0 ? {} : { fog },
|
|
803
|
+
lights,
|
|
804
|
+
materials,
|
|
805
|
+
objects,
|
|
806
|
+
truncated,
|
|
807
|
+
...bounds.isEmpty() ? {} : {
|
|
808
|
+
worldExtent: {
|
|
809
|
+
max: [bounds.max.x, bounds.max.y, bounds.max.z],
|
|
810
|
+
min: [bounds.min.x, bounds.min.y, bounds.min.z]
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
};
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
// src/three/observations.ts
|
|
482
817
|
function sampleThreeObservations(input, request) {
|
|
483
818
|
input.scene.updateMatrixWorld(true);
|
|
484
819
|
input.camera.updateMatrixWorld(true);
|
|
@@ -497,7 +832,12 @@ function sampleThreeObservations(input, request) {
|
|
|
497
832
|
...renderPerformance === void 0 ? {} : { performance: renderPerformance },
|
|
498
833
|
...renderChain === void 0 ? {} : { renderChain },
|
|
499
834
|
...input.runtimeDiagnosticsSeries === void 0 ? {} : { runtimeDiagnosticsSeries: input.runtimeDiagnosticsSeries().map((sample) => ({ ...sample })) },
|
|
500
|
-
...input.resources === void 0 ? {} : { resources: input.resources() }
|
|
835
|
+
...input.resources === void 0 ? {} : { resources: input.resources() },
|
|
836
|
+
scene: observeSceneResources(input.scene, input.camera),
|
|
837
|
+
// Only walked when a scenario asks. The node walk reads geometry, materials and world
|
|
838
|
+
// bounds per object, which is real work on a large scene, and no run should pay for it
|
|
839
|
+
// when nothing is going to read it.
|
|
840
|
+
...request.sceneNodes === void 0 || request.sceneNodes.length === 0 ? {} : { sceneNodes: observeSceneNodes(input.scene, input.camera, request.sceneNodes) }
|
|
501
841
|
};
|
|
502
842
|
}
|
|
503
843
|
function rendererPerformance(renderer) {
|
|
@@ -680,11 +1020,13 @@ function connectNativeMailbox(bridge) {
|
|
|
680
1020
|
let closed = false;
|
|
681
1021
|
let frame;
|
|
682
1022
|
const nativePointers = /* @__PURE__ */ new Map();
|
|
1023
|
+
let requestOrder = 0;
|
|
683
1024
|
let watchdogBeats = 0;
|
|
684
1025
|
let polledAtBeat = 0;
|
|
685
1026
|
let stallReported = false;
|
|
686
|
-
const respond = (response) => {
|
|
687
|
-
|
|
1027
|
+
const respond = (response, method, order) => {
|
|
1028
|
+
const sent = method === void 0 || order === void 0 ? host.respond(mailbox.response, JSON.stringify(response), response.id) : host.respond(mailbox.response, JSON.stringify(response), response.id, method, order);
|
|
1029
|
+
if (!sent) {
|
|
688
1030
|
console.error("TN_PLAYTEST_DEVICE_TRANSPORT: native mailbox response failed");
|
|
689
1031
|
}
|
|
690
1032
|
};
|
|
@@ -695,7 +1037,8 @@ function connectNativeMailbox(bridge) {
|
|
|
695
1037
|
if (raw !== void 0) {
|
|
696
1038
|
try {
|
|
697
1039
|
const request = parseRequest(JSON.parse(raw));
|
|
698
|
-
|
|
1040
|
+
const order = ++requestOrder;
|
|
1041
|
+
void dispatch(bridge, request, nativePointers).then((response) => respond(response, request.method, order));
|
|
699
1042
|
} catch (error) {
|
|
700
1043
|
respond({
|
|
701
1044
|
error: { message: error instanceof Error ? error.message : String(error) },
|
|
@@ -882,6 +1225,8 @@ function installThreePlaytestBridge(options) {
|
|
|
882
1225
|
"entity.bounds",
|
|
883
1226
|
"entity.observe",
|
|
884
1227
|
"entity.setup",
|
|
1228
|
+
"scene.nodes",
|
|
1229
|
+
"scene.observe",
|
|
885
1230
|
...options.fixedStep === void 0 ? [] : ["runtime.fixedStep"],
|
|
886
1231
|
...options.resources === void 0 ? [] : ["runtime.resources"],
|
|
887
1232
|
...options.diagnostics === void 0 ? [] : ["runtime.diagnostics"],
|
|
@@ -894,6 +1239,7 @@ function installThreePlaytestBridge(options) {
|
|
|
894
1239
|
...options.startup === void 0 ? [] : ["runtime.startup"],
|
|
895
1240
|
...options.gameplayChannels?.().includes("runtime.contacts") === true ? ["runtime.contacts"] : [],
|
|
896
1241
|
...options.gameplayChannels?.().includes("runtime.tags") === true ? ["runtime.tags"] : [],
|
|
1242
|
+
...options.gameplayChannels?.().includes("runtime.transitions") === true ? ["runtime.transitions"] : [],
|
|
897
1243
|
...options.gameplayChannels?.().includes("runtime.world") === true ? ["runtime.world"] : []
|
|
898
1244
|
];
|
|
899
1245
|
const bridge = {
|
|
@@ -911,7 +1257,7 @@ function installThreePlaytestBridge(options) {
|
|
|
911
1257
|
},
|
|
912
1258
|
applySetup: async (request) => {
|
|
913
1259
|
syncEntities(registry, options.entities);
|
|
914
|
-
applySetup(registry, options.resources, request);
|
|
1260
|
+
return applySetup(registry, options.resources, request);
|
|
915
1261
|
},
|
|
916
1262
|
...options.events === void 0 ? {} : {
|
|
917
1263
|
drainEvents: async (limit = PLAYTEST_PROTOCOL_LIMITS.maxEventsPerDrain) => {
|
|
@@ -976,6 +1322,8 @@ function syncEntities(registry, entities) {
|
|
|
976
1322
|
registry.replace(typeof entities === "function" ? entities() : entities);
|
|
977
1323
|
}
|
|
978
1324
|
function applySetup(registry, resources, request) {
|
|
1325
|
+
const entities = [];
|
|
1326
|
+
const resourceIds = [];
|
|
979
1327
|
request.entities?.forEach(({ entity, frozen, transform }) => {
|
|
980
1328
|
const object = registry.get(entity)?.object;
|
|
981
1329
|
if (object === void 0) throw new Error(`Setup entity '${entity}' is not registered.`);
|
|
@@ -984,12 +1332,15 @@ function applySetup(registry, resources, request) {
|
|
|
984
1332
|
if (transform.scale !== void 0) object.scale.fromArray(transform.scale);
|
|
985
1333
|
if (frozen === true) object.userData[PLAYTEST_FROZEN_MARKER] = true;
|
|
986
1334
|
object.updateMatrix();
|
|
1335
|
+
entities.push(entity);
|
|
987
1336
|
});
|
|
988
1337
|
request.resources?.forEach(({ id, path, value }) => {
|
|
989
1338
|
assertJsonSafe(value);
|
|
990
1339
|
if (resources?.write === void 0) throw new Error(`Resource setup '${id}' requires a writable resources provider.`);
|
|
991
1340
|
if (!resources.write(id, path, value)) throw new Error(`Resource setup '${id}' was rejected by the application provider.`);
|
|
1341
|
+
resourceIds.push(id);
|
|
992
1342
|
});
|
|
1343
|
+
return { entities, resources: resourceIds };
|
|
993
1344
|
}
|
|
994
1345
|
|
|
995
|
-
export { PLAYTEST_PHYSICS_BODY_LIMIT, PLAYTEST_PHYSICS_SAMPLE_LIMIT, ThreePlaytestPhysicsRecorder, adviseThreeRenderWorkload, connectDevicePlaytestBridge, installThreePlaytestBridge, readPlaytestEndpoint };
|
|
1346
|
+
export { PLAYTEST_PHYSICS_BODY_LIMIT, PLAYTEST_PHYSICS_SAMPLE_LIMIT, SCENE_LIGHT_CAP, SCENE_WALK_OBJECT_CAP, ThreePlaytestPhysicsRecorder, adviseThreeRenderWorkload, connectDevicePlaytestBridge, installThreePlaytestBridge, observeSceneResources, readPlaytestEndpoint };
|
package/package.json
CHANGED
|
@@ -1,8 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@threenative/playtest",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Scenario-driven playtest harness for Three.js games. Runs on plain Three.js with zero ThreeNative dependencies.",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"threenative",
|
|
8
|
+
"three",
|
|
9
|
+
"threejs",
|
|
10
|
+
"testing",
|
|
11
|
+
"playwright",
|
|
12
|
+
"e2e",
|
|
13
|
+
"gamedev"
|
|
14
|
+
],
|
|
15
|
+
"homepage": "https://github.com/ThreeNativeHQ/threenative#readme",
|
|
16
|
+
"bugs": {
|
|
17
|
+
"url": "https://github.com/ThreeNativeHQ/threenative/issues"
|
|
18
|
+
},
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/ThreeNativeHQ/threenative.git",
|
|
22
|
+
"directory": "packages/playtest"
|
|
23
|
+
},
|
|
6
24
|
"type": "module",
|
|
7
25
|
"files": [
|
|
8
26
|
"dist",
|
|
@@ -66,7 +84,7 @@
|
|
|
66
84
|
"typescript": "5.9.3"
|
|
67
85
|
},
|
|
68
86
|
"scripts": {
|
|
69
|
-
"build": "tsup --config tsup.config.ts && publint",
|
|
87
|
+
"build": "pnpm --workspace-root exec tsx scripts/generate-assertion-validators.ts --check && tsup --config tsup.config.ts && publint",
|
|
70
88
|
"typecheck": "tsc --noEmit",
|
|
71
89
|
"test": "bash __tests__/orphan-cleanup.sh && publint --strict"
|
|
72
90
|
}
|