@volter/editor-threejs 0.5.93 → 0.5.95
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/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@volter/editor-threejs",
|
|
3
3
|
"author": "Volter AI, Inc.",
|
|
4
|
-
"version": "0.5.
|
|
4
|
+
"version": "0.5.95",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
@@ -135,12 +135,12 @@
|
|
|
135
135
|
"serving": "./dist-node/serving.mjs"
|
|
136
136
|
},
|
|
137
137
|
"dependencies": {
|
|
138
|
-
"@volter/editor-project": "0.5.
|
|
138
|
+
"@volter/editor-project": "0.5.95",
|
|
139
139
|
"@sparkjsdev/spark": "^2.1.0",
|
|
140
140
|
"three.quarks": "^0.16.0",
|
|
141
141
|
"zod": "^4.3.6",
|
|
142
142
|
"typescript": "5.9.3",
|
|
143
|
-
"@volter/editor-sdk": "0.5.
|
|
143
|
+
"@volter/editor-sdk": "0.5.95",
|
|
144
144
|
"postprocessing": "6.38.3",
|
|
145
145
|
"quarks.core": "0.16.0",
|
|
146
146
|
"@fortawesome/free-solid-svg-icons": "^7.2.0"
|
|
@@ -80,6 +80,7 @@ import {
|
|
|
80
80
|
recordViewportFirstFrame,
|
|
81
81
|
} from '@volter/editor-sdk/kit/viewport-activation-timings';
|
|
82
82
|
import { bindViewportRig, runViewportFrame } from '../../viewport-door';
|
|
83
|
+
import type { StageFrameCost } from '../../viewport-api';
|
|
83
84
|
import {
|
|
84
85
|
notifyWorkspaceDocumentSelectionChanged,
|
|
85
86
|
openWorkspaceDocuments,
|
|
@@ -2089,6 +2090,54 @@ export function Object3DDocumentViewport({
|
|
|
2089
2090
|
};
|
|
2090
2091
|
|
|
2091
2092
|
host.frame = animate;
|
|
2093
|
+
/**
|
|
2094
|
+
* THE FRAME WITHOUT THE DISPLAY'S CAP (`ViewportRig.frameCost`): this stage's own `animate`,
|
|
2095
|
+
* resumed so it draws, run back to back and each waited out on the GPU with a one-pixel
|
|
2096
|
+
* read, which a real frame never does; the first frame warms and is not counted.
|
|
2097
|
+
*/
|
|
2098
|
+
const measureFrameCost = (frames: number): StageFrameCost => {
|
|
2099
|
+
if (!renderer) throw new Error('This stage has no renderer yet.');
|
|
2100
|
+
const activeRenderer = renderer;
|
|
2101
|
+
const gl = activeRenderer.getContext();
|
|
2102
|
+
const pixel = new Uint8Array(4);
|
|
2103
|
+
const times: number[] = [];
|
|
2104
|
+
for (let index = 0; index <= frames; index++) {
|
|
2105
|
+
const start = performance.now();
|
|
2106
|
+
animate(start, true);
|
|
2107
|
+
gl.readPixels(0, 0, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, pixel);
|
|
2108
|
+
if (index > 0) times.push(performance.now() - start);
|
|
2109
|
+
}
|
|
2110
|
+
const drawn = { calls: activeRenderer.info.render.calls, triangles: activeRenderer.info.render.triangles };
|
|
2111
|
+
let meshes = 0;
|
|
2112
|
+
let sceneTriangles = 0;
|
|
2113
|
+
host.scene.traverseVisible((object) => {
|
|
2114
|
+
const mesh = object as THREE.Mesh;
|
|
2115
|
+
if (!mesh.isMesh || !mesh.geometry) return;
|
|
2116
|
+
meshes++;
|
|
2117
|
+
const index = mesh.geometry.getIndex();
|
|
2118
|
+
const count = index ? index.count : (mesh.geometry.getAttribute('position')?.count ?? 0);
|
|
2119
|
+
sceneTriangles += Math.floor(count / 3) * ((mesh as THREE.InstancedMesh).count ?? 1);
|
|
2120
|
+
});
|
|
2121
|
+
const sorted = [...times].sort((a, b) => a - b);
|
|
2122
|
+
const at = (q: number) => sorted[Math.min(sorted.length - 1, Math.floor(q * sorted.length))] ?? 0;
|
|
2123
|
+
const size = activeRenderer.getDrawingBufferSize(new THREE.Vector2());
|
|
2124
|
+
const ratio = activeRenderer.getPixelRatio();
|
|
2125
|
+
const round = (value: number) => Math.round(value * 100) / 100;
|
|
2126
|
+
return {
|
|
2127
|
+
frames,
|
|
2128
|
+
medianMs: round(at(0.5)),
|
|
2129
|
+
p95Ms: round(at(0.95)),
|
|
2130
|
+
minMs: round(sorted[0] ?? 0),
|
|
2131
|
+
width: size.x,
|
|
2132
|
+
height: size.y,
|
|
2133
|
+
cssWidth: round(size.x / ratio),
|
|
2134
|
+
cssHeight: round(size.y / ratio),
|
|
2135
|
+
devicePixelRatio: ratio,
|
|
2136
|
+
drawn,
|
|
2137
|
+
scene: { meshes, triangles: sceneTriangles },
|
|
2138
|
+
drawMode: viewPresentation(documentId).drawMode,
|
|
2139
|
+
};
|
|
2140
|
+
};
|
|
2092
2141
|
rendererSessionRef.current = host.rendererSession;
|
|
2093
2142
|
if (!host.initialized) {
|
|
2094
2143
|
if (!chromeless) {
|
|
@@ -2110,6 +2159,7 @@ export function Object3DDocumentViewport({
|
|
|
2110
2159
|
drawCamera: () => host.session?.camera() ?? viewport.camera,
|
|
2111
2160
|
orbit: viewport.orbitControls,
|
|
2112
2161
|
scene: host.scene,
|
|
2162
|
+
frameCost: (frames) => measureFrameCost(frames),
|
|
2113
2163
|
},
|
|
2114
2164
|
() => null,
|
|
2115
2165
|
(kind, object) => viewport.setHelper(kind, object),
|
|
@@ -31,6 +31,7 @@ import {
|
|
|
31
31
|
viewPresentationBinding,
|
|
32
32
|
} from '@volter/editor-sdk/kit/viewport-presentation';
|
|
33
33
|
import { threeStoreForHost } from './three-state';
|
|
34
|
+
import { viewportStages } from '../viewport-door';
|
|
34
35
|
import { threeStateOf } from './three-state';
|
|
35
36
|
|
|
36
37
|
function activeObject3DDocumentSession() {
|
|
@@ -179,6 +180,34 @@ export const viewportCommands: CommandContribution['commands'] = {
|
|
|
179
180
|
}
|
|
180
181
|
return { ok: true, data: { ...documentSession.cameraPose() } };
|
|
181
182
|
}),
|
|
183
|
+
/**
|
|
184
|
+
* WHAT A FRAME OF A 3D DOCUMENT'S STAGE COSTS WHEN NOTHING CAPS IT (`ViewportRig.frameCost`):
|
|
185
|
+
* the active document's stage, or the one `stage` names by its id (a split's second area is
|
|
186
|
+
* `<documentId>#area-2`). The frame is the stage's own, so a draw mode, a split or a scene
|
|
187
|
+
* changes it the way it changes what a person sees; the reading says which it measured.
|
|
188
|
+
*/
|
|
189
|
+
'document-frame-cost': verb((_store, cmd) => {
|
|
190
|
+
const frames = cmd['frames'] ?? 60;
|
|
191
|
+
if (typeof frames !== 'number' || !Number.isInteger(frames) || frames < 1 || frames > 600)
|
|
192
|
+
return { ok: false, error: 'document-frame-cost: "frames" must be a whole number in 1..600.' };
|
|
193
|
+
const named = cmd['stage'];
|
|
194
|
+
if (named !== undefined && typeof named !== 'string')
|
|
195
|
+
return { ok: false, error: 'document-frame-cost: "stage" names a stage by its document id.' };
|
|
196
|
+
const documentId = named ?? activeWorkspaceDocumentId();
|
|
197
|
+
const stages = viewportStages();
|
|
198
|
+
const stage = stages.find((one) => one.documentId === documentId);
|
|
199
|
+
if (!stage)
|
|
200
|
+
return {
|
|
201
|
+
ok: false,
|
|
202
|
+
error:
|
|
203
|
+
`document-frame-cost: no 3D stage draws ${documentId === null ? 'the active document' : JSON.stringify(documentId)}. ` +
|
|
204
|
+
`The mounted stages are: ${stages.map((one) => one.documentId).join(', ') || 'none'}.`,
|
|
205
|
+
};
|
|
206
|
+
const measure = stage.rig().frameCost;
|
|
207
|
+
if (!measure)
|
|
208
|
+
return { ok: false, error: `document-frame-cost: the stage for ${JSON.stringify(stage.documentId)} has no frame of its own to measure.` };
|
|
209
|
+
return { ok: true, data: { stage: stage.documentId, ...measure(frames) } };
|
|
210
|
+
}, 120_000),
|
|
182
211
|
'capture-viewport': verb(async (store, cmd) => {
|
|
183
212
|
// Fresh, unthrottled on-demand capture (see EditorShellStore.captureViewportImage).
|
|
184
213
|
const requested = captureSizeFromCommand(cmd);
|
package/src/viewport-api.ts
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import type { MountedRoot } from '@volter/editor-project/adapter/root-adapter';
|
|
8
8
|
import type * as THREE from 'three';
|
|
9
|
+
import type { StageFrameCostReading } from '@volter/editor-sdk';
|
|
9
10
|
|
|
10
11
|
/** A live instance's roots, presented as the authored viewport's subject. */
|
|
11
12
|
export interface ViewportPresentation {
|
|
@@ -15,12 +16,23 @@ export interface ViewportPresentation {
|
|
|
15
16
|
dispose(): void;
|
|
16
17
|
}
|
|
17
18
|
|
|
19
|
+
/** What a frame of a stage costs, uncapped ({@link ViewportRig.frameCost}): the wire's reading
|
|
20
|
+
* without the stage's id, which the door adds. */
|
|
21
|
+
export type StageFrameCost = Omit<StageFrameCostReading, 'stage'>;
|
|
22
|
+
|
|
18
23
|
/** The authored viewport's camera rig, while a viewport is mounted. */
|
|
19
24
|
export interface ViewportRig {
|
|
20
25
|
readonly camera: THREE.PerspectiveCamera;
|
|
21
26
|
/** The camera the stage draws with NOW: {@link camera}, or the orthographic one in an
|
|
22
27
|
* orthographic view. What a document lighting or picking in step with the picture needs. */
|
|
23
28
|
drawCamera(): THREE.Camera;
|
|
29
|
+
/**
|
|
30
|
+
* WHAT A FRAME OF THIS STAGE COSTS WHEN NOTHING CAPS IT: the stage's own frame (its update,
|
|
31
|
+
* its hooks, its render and view cube) run `frames` times back to back outside
|
|
32
|
+
* `requestAnimationFrame`, each waited out on the GPU, so the number is the frame's cost and
|
|
33
|
+
* not the display's refresh. Absent on a stage with no frame of its own.
|
|
34
|
+
*/
|
|
35
|
+
frameCost?(frames: number): StageFrameCost;
|
|
24
36
|
readonly orbit: { readonly target: THREE.Vector3; enabled: boolean; update(): void };
|
|
25
37
|
/** The editor's own scene (helpers live on its editor layer). */
|
|
26
38
|
readonly scene: THREE.Scene;
|