@bluemoonfoundry/daz-ts 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +377 -2
- package/dist/animation.d.ts +129 -0
- package/dist/animation.js +276 -0
- package/dist/batch.d.ts +118 -0
- package/dist/batch.js +186 -0
- package/dist/bone.d.ts +50 -0
- package/dist/bone.js +66 -0
- package/dist/camera.d.ts +61 -0
- package/dist/camera.js +120 -0
- package/dist/cinematics.d.ts +188 -0
- package/dist/cinematics.js +165 -0
- package/dist/client.d.ts +399 -0
- package/dist/client.js +769 -0
- package/dist/dforce.d.ts +15 -0
- package/dist/dforce.js +36 -0
- package/dist/element.d.ts +51 -0
- package/dist/element.js +141 -0
- package/dist/exceptions.d.ts +124 -0
- package/dist/exceptions.js +173 -0
- package/dist/geometry.d.ts +81 -0
- package/dist/geometry.js +433 -0
- package/dist/index.d.ts +50 -0
- package/dist/index.js +36 -0
- package/dist/light.d.ts +24 -0
- package/dist/light.js +40 -0
- package/dist/lighting.d.ts +120 -0
- package/dist/lighting.js +107 -0
- package/dist/material.d.ts +27 -0
- package/dist/material.js +63 -0
- package/dist/materials.d.ts +107 -0
- package/dist/materials.js +165 -0
- package/dist/math3.d.ts +204 -0
- package/dist/math3.js +502 -0
- package/dist/modifier.d.ts +14 -0
- package/dist/modifier.js +24 -0
- package/dist/morph.d.ts +11 -0
- package/dist/morph.js +24 -0
- package/dist/node.d.ts +196 -0
- package/dist/node.js +447 -0
- package/dist/polling.d.ts +24 -0
- package/dist/polling.js +50 -0
- package/dist/pose.d.ts +82 -0
- package/dist/pose.js +295 -0
- package/dist/poses.d.ts +54 -0
- package/dist/poses.js +40 -0
- package/dist/property.d.ts +64 -0
- package/dist/property.js +125 -0
- package/dist/render.d.ts +242 -0
- package/dist/render.js +811 -0
- package/dist/renderApi.d.ts +124 -0
- package/dist/renderApi.js +235 -0
- package/dist/result.d.ts +15 -0
- package/dist/result.js +1 -0
- package/dist/scene.d.ts +154 -0
- package/dist/scene.js +584 -0
- package/dist/sceneEvents.d.ts +63 -0
- package/dist/sceneEvents.js +102 -0
- package/dist/sceneState.d.ts +167 -0
- package/dist/sceneState.js +430 -0
- package/dist/scriptBuilder.d.ts +41 -0
- package/dist/scriptBuilder.js +72 -0
- package/dist/shotGeometry.d.ts +49 -0
- package/dist/shotGeometry.js +76 -0
- package/dist/skeleton.d.ts +120 -0
- package/dist/skeleton.js +561 -0
- package/dist/timeline.d.ts +24 -0
- package/dist/timeline.js +39 -0
- package/dist/undo.d.ts +24 -0
- package/dist/undo.js +45 -0
- package/dist/version.d.ts +31 -0
- package/dist/version.js +36 -0
- package/dist/viewport.d.ts +58 -0
- package/dist/viewport.js +239 -0
- package/package.json +52 -4
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { DazClient } from "./client.js";
|
|
2
|
+
/**
|
|
3
|
+
* Timeline and playback control for the active scene. A thin wrapper
|
|
4
|
+
* around the `Scene` playback API — `DazScene` offers the same frame/range
|
|
5
|
+
* methods; use `DazTimeline` when a focused, dedicated object is preferred.
|
|
6
|
+
*/
|
|
7
|
+
export declare class DazTimeline {
|
|
8
|
+
private readonly client;
|
|
9
|
+
constructor(client?: DazClient);
|
|
10
|
+
/** Current timeline frame (read/write). */
|
|
11
|
+
frame(): Promise<number | null>;
|
|
12
|
+
setFrame(value: number): Promise<void>;
|
|
13
|
+
/** Current time in DAZ ticks (use {@link frame} for frame-based access). */
|
|
14
|
+
time(): Promise<number | null>;
|
|
15
|
+
/** Number of DAZ ticks per frame (read-only). */
|
|
16
|
+
timeStep(): Promise<number | null>;
|
|
17
|
+
/** Animation range as `{start, end}` in frames (read-only). */
|
|
18
|
+
frameRange(): Promise<{
|
|
19
|
+
start: number;
|
|
20
|
+
end: number;
|
|
21
|
+
} | null>;
|
|
22
|
+
play(): Promise<void>;
|
|
23
|
+
pause(): Promise<void>;
|
|
24
|
+
}
|
package/dist/timeline.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { DazClient as DazClientImpl } from "./client.js";
|
|
2
|
+
import { ScriptBuilder } from "./scriptBuilder.js";
|
|
3
|
+
/**
|
|
4
|
+
* Timeline and playback control for the active scene. A thin wrapper
|
|
5
|
+
* around the `Scene` playback API — `DazScene` offers the same frame/range
|
|
6
|
+
* methods; use `DazTimeline` when a focused, dedicated object is preferred.
|
|
7
|
+
*/
|
|
8
|
+
export class DazTimeline {
|
|
9
|
+
client;
|
|
10
|
+
constructor(client) {
|
|
11
|
+
this.client = client ?? new DazClientImpl();
|
|
12
|
+
}
|
|
13
|
+
/** Current timeline frame (read/write). */
|
|
14
|
+
async frame() {
|
|
15
|
+
return (await this.client.execute(ScriptBuilder.iife("return Scene.getFrame();"))).value;
|
|
16
|
+
}
|
|
17
|
+
async setFrame(value) {
|
|
18
|
+
await this.client.execute(ScriptBuilder.iife(`Scene.setFrame(${ScriptBuilder.serializeArg(Math.trunc(value))});`));
|
|
19
|
+
}
|
|
20
|
+
/** Current time in DAZ ticks (use {@link frame} for frame-based access). */
|
|
21
|
+
async time() {
|
|
22
|
+
return (await this.client.execute(ScriptBuilder.iife("return Scene.getTime().valueOf();"))).value;
|
|
23
|
+
}
|
|
24
|
+
/** Number of DAZ ticks per frame (read-only). */
|
|
25
|
+
async timeStep() {
|
|
26
|
+
return (await this.client.execute(ScriptBuilder.iife("return Scene.getTimeStep();"))).value;
|
|
27
|
+
}
|
|
28
|
+
/** Animation range as `{start, end}` in frames (read-only). */
|
|
29
|
+
async frameRange() {
|
|
30
|
+
const script = ScriptBuilder.iife("return { start: Scene.getAnimRange().start, end: Scene.getAnimRange().end };");
|
|
31
|
+
return (await this.client.execute(script)).value;
|
|
32
|
+
}
|
|
33
|
+
async play() {
|
|
34
|
+
await this.client.execute(ScriptBuilder.iife("Scene.play();"));
|
|
35
|
+
}
|
|
36
|
+
async pause() {
|
|
37
|
+
await this.client.execute(ScriptBuilder.iife("Scene.stop();"));
|
|
38
|
+
}
|
|
39
|
+
}
|
package/dist/undo.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { DazClient } from "./client.js";
|
|
2
|
+
/**
|
|
3
|
+
* Groups DAZ Studio operations into a single undo step. TypeScript has no
|
|
4
|
+
* `with` statement, so this is not a context manager (unlike dazpy's
|
|
5
|
+
* `UndoGroup`) — call {@link begin}, then either {@link commit} or
|
|
6
|
+
* {@link cancel}, or prefer the {@link withUndo} helper / `DazScene.undo()`
|
|
7
|
+
* which does this for you around a callback.
|
|
8
|
+
*/
|
|
9
|
+
export declare class UndoGroup {
|
|
10
|
+
private readonly client;
|
|
11
|
+
private readonly label;
|
|
12
|
+
constructor(client: DazClient, label: string);
|
|
13
|
+
begin(): Promise<void>;
|
|
14
|
+
/** Commit the grouped changes as a single undo step labeled per the constructor. */
|
|
15
|
+
commit(): Promise<void>;
|
|
16
|
+
/** Discard the undo grouping (the underlying changes are not reverted; this only cancels the *grouping*, matching dazpy's `cancelUndo()`). */
|
|
17
|
+
cancel(): Promise<void>;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Run `fn` inside an {@link UndoGroup}: `begin()`, then `fn()`, then
|
|
21
|
+
* `commit()` on success or `cancel()` (then rethrow) if `fn` throws —
|
|
22
|
+
* the TS equivalent of dazpy's `with scene.undo(label): ...`.
|
|
23
|
+
*/
|
|
24
|
+
export declare function withUndo<T>(client: DazClient, label: string, fn: () => Promise<T>): Promise<T>;
|
package/dist/undo.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { ScriptBuilder } from "./scriptBuilder.js";
|
|
2
|
+
/**
|
|
3
|
+
* Groups DAZ Studio operations into a single undo step. TypeScript has no
|
|
4
|
+
* `with` statement, so this is not a context manager (unlike dazpy's
|
|
5
|
+
* `UndoGroup`) — call {@link begin}, then either {@link commit} or
|
|
6
|
+
* {@link cancel}, or prefer the {@link withUndo} helper / `DazScene.undo()`
|
|
7
|
+
* which does this for you around a callback.
|
|
8
|
+
*/
|
|
9
|
+
export class UndoGroup {
|
|
10
|
+
client;
|
|
11
|
+
label;
|
|
12
|
+
constructor(client, label) {
|
|
13
|
+
this.client = client;
|
|
14
|
+
this.label = label;
|
|
15
|
+
}
|
|
16
|
+
async begin() {
|
|
17
|
+
await this.client.execute(ScriptBuilder.iife("beginUndo();"));
|
|
18
|
+
}
|
|
19
|
+
/** Commit the grouped changes as a single undo step labeled per the constructor. */
|
|
20
|
+
async commit() {
|
|
21
|
+
await this.client.execute(ScriptBuilder.iife(`acceptUndo(${ScriptBuilder.escapeString(this.label)});`));
|
|
22
|
+
}
|
|
23
|
+
/** Discard the undo grouping (the underlying changes are not reverted; this only cancels the *grouping*, matching dazpy's `cancelUndo()`). */
|
|
24
|
+
async cancel() {
|
|
25
|
+
await this.client.execute(ScriptBuilder.iife("cancelUndo();"));
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Run `fn` inside an {@link UndoGroup}: `begin()`, then `fn()`, then
|
|
30
|
+
* `commit()` on success or `cancel()` (then rethrow) if `fn` throws —
|
|
31
|
+
* the TS equivalent of dazpy's `with scene.undo(label): ...`.
|
|
32
|
+
*/
|
|
33
|
+
export async function withUndo(client, label, fn) {
|
|
34
|
+
const group = new UndoGroup(client, label);
|
|
35
|
+
await group.begin();
|
|
36
|
+
try {
|
|
37
|
+
const result = await fn();
|
|
38
|
+
await group.commit();
|
|
39
|
+
return result;
|
|
40
|
+
}
|
|
41
|
+
catch (err) {
|
|
42
|
+
await group.cancel();
|
|
43
|
+
throw err;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plugin version compatibility check, the counterpart of dazpy's
|
|
3
|
+
* `MIN_SERVER_VERSION`. Unlike dazpy, daz-ts never checks on its own: call
|
|
4
|
+
* {@link DazClient.checkServerVersion} when you want to know.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Oldest DazScriptServer plugin (major.minor) this daz-ts needs. 2.11 added
|
|
8
|
+
* `/capabilities`, the artifact routes, and `cancel_requested` cancellation,
|
|
9
|
+
* all of which `DazClient` uses. Raise it only when daz-ts starts calling a
|
|
10
|
+
* plugin route or field that older plugins lack.
|
|
11
|
+
*/
|
|
12
|
+
export declare const MIN_SERVER_VERSION = "2.11";
|
|
13
|
+
/** Result of one plugin version check. */
|
|
14
|
+
export interface VersionCheck {
|
|
15
|
+
/** Base URL of the checked plugin, e.g. `"http://127.0.0.1:18811"`. */
|
|
16
|
+
serverUrl: string;
|
|
17
|
+
/** Plugin version from `GET /status`; `null` if it didn't report one. */
|
|
18
|
+
serverVersion: string | null;
|
|
19
|
+
/** {@link MIN_SERVER_VERSION} at check time. */
|
|
20
|
+
minServerVersion: string;
|
|
21
|
+
/** The plugin's per-run identity, if it reported one. */
|
|
22
|
+
serverInstanceId: string | null;
|
|
23
|
+
/** `true`/`false`; `null` when a version couldn't be parsed. */
|
|
24
|
+
compatible: boolean | null;
|
|
25
|
+
/** Upgrade advice when `compatible` is `false`, else `null`. */
|
|
26
|
+
message: string | null;
|
|
27
|
+
}
|
|
28
|
+
/** Return `[major, minor]` from a version string like `"2.10.0"` or `"v2.11"`, or `null`. */
|
|
29
|
+
export declare function parseVersion(value: unknown): [number, number] | null;
|
|
30
|
+
/** Compare the version a `/status` body reports against {@link MIN_SERVER_VERSION}. */
|
|
31
|
+
export declare function evaluateServerVersion(serverUrl: string, status: unknown): VersionCheck;
|
package/dist/version.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plugin version compatibility check, the counterpart of dazpy's
|
|
3
|
+
* `MIN_SERVER_VERSION`. Unlike dazpy, daz-ts never checks on its own: call
|
|
4
|
+
* {@link DazClient.checkServerVersion} when you want to know.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Oldest DazScriptServer plugin (major.minor) this daz-ts needs. 2.11 added
|
|
8
|
+
* `/capabilities`, the artifact routes, and `cancel_requested` cancellation,
|
|
9
|
+
* all of which `DazClient` uses. Raise it only when daz-ts starts calling a
|
|
10
|
+
* plugin route or field that older plugins lack.
|
|
11
|
+
*/
|
|
12
|
+
export const MIN_SERVER_VERSION = "2.11";
|
|
13
|
+
const RELEASES_URL = "https://github.com/bluemoonfoundry/daz-script-server/releases";
|
|
14
|
+
/** Return `[major, minor]` from a version string like `"2.10.0"` or `"v2.11"`, or `null`. */
|
|
15
|
+
export function parseVersion(value) {
|
|
16
|
+
if (typeof value !== "string")
|
|
17
|
+
return null;
|
|
18
|
+
const m = /^\s*v?(\d+)\.(\d+)/.exec(value);
|
|
19
|
+
return m ? [Number(m[1]), Number(m[2])] : null;
|
|
20
|
+
}
|
|
21
|
+
/** Compare the version a `/status` body reports against {@link MIN_SERVER_VERSION}. */
|
|
22
|
+
export function evaluateServerVersion(serverUrl, status) {
|
|
23
|
+
const body = typeof status === "object" && status !== null ? status : {};
|
|
24
|
+
const serverVersion = typeof body.version === "string" ? body.version : null;
|
|
25
|
+
const instance = body.server_instance_id;
|
|
26
|
+
const serverInstanceId = typeof instance === "string" && instance ? instance : null;
|
|
27
|
+
const server = parseVersion(serverVersion);
|
|
28
|
+
const needed = parseVersion(MIN_SERVER_VERSION);
|
|
29
|
+
const compatible = server === null || needed === null ? null : server[0] > needed[0] || (server[0] === needed[0] && server[1] >= needed[1]);
|
|
30
|
+
const message = compatible === false
|
|
31
|
+
? `Daz Studio plugin at ${serverUrl} is version ${serverVersion}; daz-ts needs ` +
|
|
32
|
+
`${MIN_SERVER_VERSION} or newer. Upgrade the DazScriptServer plugin in the ` +
|
|
33
|
+
`Daz Studio instance at that address (${RELEASES_URL}).`
|
|
34
|
+
: null;
|
|
35
|
+
return { serverUrl, serverVersion, minServerVersion: MIN_SERVER_VERSION, serverInstanceId, compatible, message };
|
|
36
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { DazClient } from "./client.js";
|
|
2
|
+
/** Viewport control: draw style, size query, and screenshot capture for DAZ Studio's active 3D viewport. */
|
|
3
|
+
export declare class DazViewport {
|
|
4
|
+
private readonly client;
|
|
5
|
+
constructor(client?: DazClient);
|
|
6
|
+
/** `true` if an active 3D viewport is accessible. */
|
|
7
|
+
isAvailable(): Promise<boolean>;
|
|
8
|
+
/** Current draw style label (e.g. `"NVIDIA Iray"`). */
|
|
9
|
+
drawStyle(): Promise<string | null>;
|
|
10
|
+
/**
|
|
11
|
+
* Set the viewport's draw style (preview quality). Accepts a friendly
|
|
12
|
+
* alias (`"wireframe"`, `"wire_bounding_box"`, `"smooth_shaded"`,
|
|
13
|
+
* `"texture_shaded"`, `"iray"`) or a raw DAZ Studio label directly.
|
|
14
|
+
* @throws Error if the style isn't recognized — `setUserDrawStyle()`
|
|
15
|
+
* silently no-ops on an unknown label, so this reads the style back
|
|
16
|
+
* afterward and throws if it didn't change (and wasn't already applied).
|
|
17
|
+
*/
|
|
18
|
+
setDrawStyle(style: string): Promise<void>;
|
|
19
|
+
/** Viewport dimensions as `{width, height}`. */
|
|
20
|
+
getSize(): Promise<{
|
|
21
|
+
width: number;
|
|
22
|
+
height: number;
|
|
23
|
+
} | null>;
|
|
24
|
+
/**
|
|
25
|
+
* Not supported — `Dz3DViewport` does not expose resize via DazScript.
|
|
26
|
+
* Resize the DAZ Studio viewport window manually before calling {@link capture}.
|
|
27
|
+
*/
|
|
28
|
+
setSize(_width: number, _height: number): never;
|
|
29
|
+
/**
|
|
30
|
+
* Capture the active 3D viewport to a PNG/JPEG file.
|
|
31
|
+
*
|
|
32
|
+
* Split into two script round-trips deliberately: every viewport-state
|
|
33
|
+
* change this method makes to prepare the shot (toggling overlays,
|
|
34
|
+
* deselecting, changing the backdrop) invalidates DAZ Studio's Iray
|
|
35
|
+
* real-time preview and restarts its progressive convergence. A single
|
|
36
|
+
* script that invalidates the preview and calls `captureImage()` on the
|
|
37
|
+
* next line grabs the framebuffer at essentially sample 0-1 — confirmed
|
|
38
|
+
* live to make fully-clothed figures look nude (clothing layers too
|
|
39
|
+
* thin/transparent to resolve at that sample count). Waiting in this
|
|
40
|
+
* method *before* calling a combined script wouldn't help, since the
|
|
41
|
+
* invalidate-then-grab both happen inside one call with nothing outside
|
|
42
|
+
* it to wait on — hence a real `convergenceWait` sleep between two
|
|
43
|
+
* separate `execute()` calls: one to invalidate (and kick off a fresh
|
|
44
|
+
* convergence pass), one to grab the now-converged frame and restore state.
|
|
45
|
+
*
|
|
46
|
+
* @param width,height Accepted for API compatibility but ignored — `Dz3DViewport` does not expose resize via DazScript.
|
|
47
|
+
* @param hideOverlays When `true` (default), axes/floor/pose-tool/aspect-frame and the primary selection are hidden for the capture and restored after.
|
|
48
|
+
* @param backdropColor Temporary `[r,g,b]` viewport background for the capture, restored after.
|
|
49
|
+
* @param convergenceWait Seconds to sleep between the two passes (default `3.0`); `0` skips the wait (accepting a possibly-unconverged capture).
|
|
50
|
+
*/
|
|
51
|
+
capture(path: string, opts?: {
|
|
52
|
+
width?: number;
|
|
53
|
+
height?: number;
|
|
54
|
+
hideOverlays?: boolean;
|
|
55
|
+
backdropColor?: [number, number, number];
|
|
56
|
+
convergenceWait?: number;
|
|
57
|
+
}): Promise<string>;
|
|
58
|
+
}
|
package/dist/viewport.js
ADDED
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
import { DazClient as DazClientImpl } from "./client.js";
|
|
2
|
+
import { ScriptBuilder } from "./scriptBuilder.js";
|
|
3
|
+
const VIEWPORT_EXPR = "MainWindow.getViewportMgr().getActiveViewport().get3DViewport()";
|
|
4
|
+
/**
|
|
5
|
+
* Friendly aliases for `Dz3DViewport.setUserDrawStyle()`'s label strings.
|
|
6
|
+
* Confirmed against a live instance: `setUserDrawStyle()` takes the exact
|
|
7
|
+
* label shown in the viewport's draw-style dropdown and silently no-ops if
|
|
8
|
+
* the label isn't recognized — empirical, not derived from an SDK enum. A
|
|
9
|
+
* raw label string (e.g. `"NVIDIA Iray"`) is also accepted directly.
|
|
10
|
+
*/
|
|
11
|
+
const DRAW_STYLE_ALIASES = {
|
|
12
|
+
wire_bounding_box: "Wire Bounding Box",
|
|
13
|
+
wireframe: "Wireframe",
|
|
14
|
+
smooth_shaded: "Smooth Shaded",
|
|
15
|
+
texture_shaded: "Texture Shaded",
|
|
16
|
+
iray: "NVIDIA Iray",
|
|
17
|
+
};
|
|
18
|
+
/** Viewport control: draw style, size query, and screenshot capture for DAZ Studio's active 3D viewport. */
|
|
19
|
+
export class DazViewport {
|
|
20
|
+
client;
|
|
21
|
+
constructor(client) {
|
|
22
|
+
this.client = client ?? new DazClientImpl();
|
|
23
|
+
}
|
|
24
|
+
/** `true` if an active 3D viewport is accessible. */
|
|
25
|
+
async isAvailable() {
|
|
26
|
+
const script = ScriptBuilder.iife(`var vp = ${VIEWPORT_EXPR}; return (vp !== null && vp !== undefined);`);
|
|
27
|
+
return Boolean((await this.client.execute(script)).value);
|
|
28
|
+
}
|
|
29
|
+
/** Current draw style label (e.g. `"NVIDIA Iray"`). */
|
|
30
|
+
async drawStyle() {
|
|
31
|
+
const script = ScriptBuilder.iife(`var vp = ${VIEWPORT_EXPR}; if (!vp) return null; return vp.getUserDrawStyle();`);
|
|
32
|
+
return (await this.client.execute(script)).value;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Set the viewport's draw style (preview quality). Accepts a friendly
|
|
36
|
+
* alias (`"wireframe"`, `"wire_bounding_box"`, `"smooth_shaded"`,
|
|
37
|
+
* `"texture_shaded"`, `"iray"`) or a raw DAZ Studio label directly.
|
|
38
|
+
* @throws Error if the style isn't recognized — `setUserDrawStyle()`
|
|
39
|
+
* silently no-ops on an unknown label, so this reads the style back
|
|
40
|
+
* afterward and throws if it didn't change (and wasn't already applied).
|
|
41
|
+
*/
|
|
42
|
+
async setDrawStyle(style) {
|
|
43
|
+
const resolved = DRAW_STYLE_ALIASES[style.trim().toLowerCase()] ?? style;
|
|
44
|
+
const script = ScriptBuilder.iife(`
|
|
45
|
+
var vp = ${VIEWPORT_EXPR};
|
|
46
|
+
if (!vp) return null;
|
|
47
|
+
var before = vp.getUserDrawStyle();
|
|
48
|
+
vp.setUserDrawStyle(${ScriptBuilder.escapeString(resolved)});
|
|
49
|
+
return {before: before, after: vp.getUserDrawStyle()};
|
|
50
|
+
`);
|
|
51
|
+
const result = (await this.client.execute(script)).value;
|
|
52
|
+
if (result === null)
|
|
53
|
+
return;
|
|
54
|
+
if (result.after !== resolved && result.after === result.before) {
|
|
55
|
+
throw new Error(`Unknown viewport draw style: ${JSON.stringify(style)}`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/** Viewport dimensions as `{width, height}`. */
|
|
59
|
+
async getSize() {
|
|
60
|
+
const script = ScriptBuilder.iife(`
|
|
61
|
+
var vp = ${VIEWPORT_EXPR};
|
|
62
|
+
if (!vp) return null;
|
|
63
|
+
var r = vp.geometry;
|
|
64
|
+
return {width: r.width, height: r.height};
|
|
65
|
+
`);
|
|
66
|
+
return (await this.client.execute(script)).value;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Not supported — `Dz3DViewport` does not expose resize via DazScript.
|
|
70
|
+
* Resize the DAZ Studio viewport window manually before calling {@link capture}.
|
|
71
|
+
*/
|
|
72
|
+
setSize(_width, _height) {
|
|
73
|
+
throw new Error("Viewport resize via DazScript is not supported. Resize the DAZ Studio viewport window manually.");
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Capture the active 3D viewport to a PNG/JPEG file.
|
|
77
|
+
*
|
|
78
|
+
* Split into two script round-trips deliberately: every viewport-state
|
|
79
|
+
* change this method makes to prepare the shot (toggling overlays,
|
|
80
|
+
* deselecting, changing the backdrop) invalidates DAZ Studio's Iray
|
|
81
|
+
* real-time preview and restarts its progressive convergence. A single
|
|
82
|
+
* script that invalidates the preview and calls `captureImage()` on the
|
|
83
|
+
* next line grabs the framebuffer at essentially sample 0-1 — confirmed
|
|
84
|
+
* live to make fully-clothed figures look nude (clothing layers too
|
|
85
|
+
* thin/transparent to resolve at that sample count). Waiting in this
|
|
86
|
+
* method *before* calling a combined script wouldn't help, since the
|
|
87
|
+
* invalidate-then-grab both happen inside one call with nothing outside
|
|
88
|
+
* it to wait on — hence a real `convergenceWait` sleep between two
|
|
89
|
+
* separate `execute()` calls: one to invalidate (and kick off a fresh
|
|
90
|
+
* convergence pass), one to grab the now-converged frame and restore state.
|
|
91
|
+
*
|
|
92
|
+
* @param width,height Accepted for API compatibility but ignored — `Dz3DViewport` does not expose resize via DazScript.
|
|
93
|
+
* @param hideOverlays When `true` (default), axes/floor/pose-tool/aspect-frame and the primary selection are hidden for the capture and restored after.
|
|
94
|
+
* @param backdropColor Temporary `[r,g,b]` viewport background for the capture, restored after.
|
|
95
|
+
* @param convergenceWait Seconds to sleep between the two passes (default `3.0`); `0` skips the wait (accepting a possibly-unconverged capture).
|
|
96
|
+
*/
|
|
97
|
+
async capture(path, opts = {}) {
|
|
98
|
+
const { hideOverlays = true, backdropColor, convergenceWait = 3.0 } = opts;
|
|
99
|
+
const jsPath = ScriptBuilder.escapeString(path);
|
|
100
|
+
const bgCaptureJs = backdropColor !== undefined ? "var prevBg = vp.background;" : "";
|
|
101
|
+
let bgApplyJs = "";
|
|
102
|
+
if (backdropColor !== undefined) {
|
|
103
|
+
const [r, g, b] = backdropColor.map((c) => Math.trunc(c));
|
|
104
|
+
const hex = `#${r.toString(16).padStart(2, "0")}${g.toString(16).padStart(2, "0")}${b.toString(16).padStart(2, "0")}`;
|
|
105
|
+
bgApplyJs = `vp.background = new QColor(${ScriptBuilder.escapeString(hex)});`;
|
|
106
|
+
}
|
|
107
|
+
const bgReturnField = backdropColor !== undefined ? ", bg: prevBg" : "";
|
|
108
|
+
if (hideOverlays) {
|
|
109
|
+
const prepareScript = ScriptBuilder.iife(`
|
|
110
|
+
var vp = ${VIEWPORT_EXPR};
|
|
111
|
+
if (!vp) return null;
|
|
112
|
+
|
|
113
|
+
var prevAxes = vp.axesOn;
|
|
114
|
+
var prevFloor = vp.floorStyle;
|
|
115
|
+
var prevPose = vp.showPoseTool;
|
|
116
|
+
var prevAspect = vp.aspectOn;
|
|
117
|
+
var prevThirds = vp.thirdsGuideOn;
|
|
118
|
+
var prevToolBarMode = vp.toolBarMode;
|
|
119
|
+
${bgCaptureJs}
|
|
120
|
+
|
|
121
|
+
var prevSelection = Scene.getPrimarySelection();
|
|
122
|
+
var prevSelectionName = prevSelection ? prevSelection.getName() : null;
|
|
123
|
+
var prevSelectionSkeletonName = null;
|
|
124
|
+
if (prevSelection && prevSelection.isBoneSelectingNode && prevSelection.isBoneSelectingNode()) {
|
|
125
|
+
var _selSkel = prevSelection.getSkeleton ? prevSelection.getSkeleton() : null;
|
|
126
|
+
if (_selSkel) prevSelectionSkeletonName = _selSkel.getName();
|
|
127
|
+
}
|
|
128
|
+
var tnNode = Scene.findNodeByLabel("Tonemapper Options");
|
|
129
|
+
var envNode = Scene.findNodeByLabel("Environment Options");
|
|
130
|
+
var prevTnVisible = tnNode ? tnNode.isVisibleInViewport() : null;
|
|
131
|
+
var prevEnvVisible = envNode ? envNode.isVisibleInViewport() : null;
|
|
132
|
+
|
|
133
|
+
vp.axesOn = false;
|
|
134
|
+
vp.floorStyle = 0;
|
|
135
|
+
vp.showPoseTool = false;
|
|
136
|
+
vp.aspectOn = false;
|
|
137
|
+
vp.thirdsGuideOn = false;
|
|
138
|
+
vp.toolBarMode = 0;
|
|
139
|
+
${bgApplyJs}
|
|
140
|
+
|
|
141
|
+
Scene.setPrimarySelection(null);
|
|
142
|
+
if (tnNode) tnNode.setVisibleInViewport(false);
|
|
143
|
+
if (envNode) envNode.setVisibleInViewport(false);
|
|
144
|
+
|
|
145
|
+
vp.updateGL();
|
|
146
|
+
|
|
147
|
+
return {
|
|
148
|
+
axesOn: prevAxes, floorStyle: prevFloor, showPoseTool: prevPose,
|
|
149
|
+
aspectOn: prevAspect, thirdsGuideOn: prevThirds, toolBarMode: prevToolBarMode,
|
|
150
|
+
selectionName: prevSelectionName,
|
|
151
|
+
selectionSkeletonName: prevSelectionSkeletonName,
|
|
152
|
+
tnVisible: prevTnVisible, envVisible: prevEnvVisible${bgReturnField}
|
|
153
|
+
};
|
|
154
|
+
`);
|
|
155
|
+
const prevState = (await this.client.execute(prepareScript)).value ?? {};
|
|
156
|
+
if (convergenceWait > 0) {
|
|
157
|
+
await new Promise((resolve) => setTimeout(resolve, convergenceWait * 1000));
|
|
158
|
+
}
|
|
159
|
+
let restoreBgJs = "";
|
|
160
|
+
if (backdropColor !== undefined && prevState.bg !== null && prevState.bg !== undefined) {
|
|
161
|
+
const pb = prevState.bg;
|
|
162
|
+
restoreBgJs = `vp.background = new QColor(${ScriptBuilder.serializeArg(Math.trunc(pb.r))}, ${ScriptBuilder.serializeArg(Math.trunc(pb.g))}, ${ScriptBuilder.serializeArg(Math.trunc(pb.b))}, ${ScriptBuilder.serializeArg(Math.trunc(pb.a ?? 255))});`;
|
|
163
|
+
}
|
|
164
|
+
// vp is deliberately re-fetched (not assumed available): it can become unavailable during the real
|
|
165
|
+
// wall-clock convergenceWait sleep. Scene-level restoration always runs; only viewport-specific
|
|
166
|
+
// properties and the capture itself are skipped if vp is gone.
|
|
167
|
+
const finishScript = ScriptBuilder.iife(`
|
|
168
|
+
var vp = ${VIEWPORT_EXPR};
|
|
169
|
+
var prev = ${JSON.stringify(prevState)};
|
|
170
|
+
var img = null;
|
|
171
|
+
|
|
172
|
+
if (vp) {
|
|
173
|
+
vp.updateGL();
|
|
174
|
+
img = vp.captureImage();
|
|
175
|
+
|
|
176
|
+
vp.axesOn = prev.axesOn;
|
|
177
|
+
vp.floorStyle = prev.floorStyle;
|
|
178
|
+
vp.showPoseTool = prev.showPoseTool;
|
|
179
|
+
vp.aspectOn = prev.aspectOn;
|
|
180
|
+
vp.thirdsGuideOn = prev.thirdsGuideOn;
|
|
181
|
+
vp.toolBarMode = prev.toolBarMode;
|
|
182
|
+
${restoreBgJs}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
var prevSel = null;
|
|
186
|
+
if (prev.selectionName) {
|
|
187
|
+
prevSel = Scene.findNode(prev.selectionName);
|
|
188
|
+
if (!prevSel && prev.selectionSkeletonName) {
|
|
189
|
+
var _selSkel = Scene.findNode(prev.selectionSkeletonName);
|
|
190
|
+
if (_selSkel && _selSkel.findBone) prevSel = _selSkel.findBone(prev.selectionName);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
Scene.setPrimarySelection(prevSel);
|
|
194
|
+
var tnNode = Scene.findNodeByLabel("Tonemapper Options");
|
|
195
|
+
var envNode = Scene.findNodeByLabel("Environment Options");
|
|
196
|
+
if (tnNode && prev.tnVisible !== null) tnNode.setVisibleInViewport(prev.tnVisible);
|
|
197
|
+
if (envNode && prev.envVisible !== null) envNode.setVisibleInViewport(prev.envVisible);
|
|
198
|
+
|
|
199
|
+
if (vp) vp.updateGL();
|
|
200
|
+
|
|
201
|
+
if (!img) return null;
|
|
202
|
+
img.save(${jsPath});
|
|
203
|
+
return ${jsPath};
|
|
204
|
+
`);
|
|
205
|
+
const result = (await this.client.execute(finishScript)).value;
|
|
206
|
+
return result ?? path;
|
|
207
|
+
}
|
|
208
|
+
const prepareScript = ScriptBuilder.iife(`
|
|
209
|
+
var vp = ${VIEWPORT_EXPR};
|
|
210
|
+
if (!vp) return null;
|
|
211
|
+
${bgCaptureJs}
|
|
212
|
+
${bgApplyJs}
|
|
213
|
+
vp.updateGL();
|
|
214
|
+
return {"ok": true${bgReturnField}};
|
|
215
|
+
`);
|
|
216
|
+
const prepResult = (await this.client.execute(prepareScript)).value ?? {};
|
|
217
|
+
if (prepResult.ok && convergenceWait > 0) {
|
|
218
|
+
await new Promise((resolve) => setTimeout(resolve, convergenceWait * 1000));
|
|
219
|
+
}
|
|
220
|
+
let restoreBgJs = "";
|
|
221
|
+
if (backdropColor !== undefined && prepResult.bg !== null && prepResult.bg !== undefined) {
|
|
222
|
+
const pb = prepResult.bg;
|
|
223
|
+
restoreBgJs = `vp.background = new QColor(${ScriptBuilder.serializeArg(Math.trunc(pb.r))}, ${ScriptBuilder.serializeArg(Math.trunc(pb.g))}, ${ScriptBuilder.serializeArg(Math.trunc(pb.b))}, ${ScriptBuilder.serializeArg(Math.trunc(pb.a ?? 255))});`;
|
|
224
|
+
}
|
|
225
|
+
const finishScript = ScriptBuilder.iife(`
|
|
226
|
+
var vp = ${VIEWPORT_EXPR};
|
|
227
|
+
if (!vp) return null;
|
|
228
|
+
vp.updateGL();
|
|
229
|
+
var img = vp.captureImage();
|
|
230
|
+
${restoreBgJs}
|
|
231
|
+
vp.updateGL();
|
|
232
|
+
if (!img) return null;
|
|
233
|
+
img.save(${jsPath});
|
|
234
|
+
return ${jsPath};
|
|
235
|
+
`);
|
|
236
|
+
const result = (await this.client.execute(finishScript)).value;
|
|
237
|
+
return result ?? path;
|
|
238
|
+
}
|
|
239
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,54 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bluemoonfoundry/daz-ts",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "TypeScript SDK for the DAZ Studio Script Server",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./package.json": "./package.json"
|
|
14
|
+
},
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "git+https://github.com/bluemoonfoundry/daz-script-server.git",
|
|
19
|
+
"directory": "daz-ts"
|
|
20
|
+
},
|
|
21
|
+
"homepage": "https://github.com/bluemoonfoundry/daz-script-server/tree/master/daz-ts#readme",
|
|
22
|
+
"bugs": {
|
|
23
|
+
"url": "https://github.com/bluemoonfoundry/daz-script-server/issues"
|
|
24
|
+
},
|
|
25
|
+
"keywords": [
|
|
26
|
+
"daz",
|
|
27
|
+
"daz-studio",
|
|
28
|
+
"dazscript",
|
|
29
|
+
"3d",
|
|
30
|
+
"sdk"
|
|
31
|
+
],
|
|
32
|
+
"engines": {
|
|
33
|
+
"node": ">=18"
|
|
34
|
+
},
|
|
35
|
+
"files": [
|
|
36
|
+
"dist"
|
|
37
|
+
],
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"access": "public"
|
|
40
|
+
},
|
|
41
|
+
"scripts": {
|
|
42
|
+
"prepare": "npm run build",
|
|
43
|
+
"build": "tsc -p tsconfig.json",
|
|
44
|
+
"typecheck": "tsc -p tsconfig.typecheck.json",
|
|
45
|
+
"test": "vitest run test/unit",
|
|
46
|
+
"test:integration": "vitest run test/integration",
|
|
47
|
+
"test:watch": "vitest"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@types/node": "^20.14.0",
|
|
51
|
+
"typescript": "^5.5.0",
|
|
52
|
+
"vitest": "^2.0.0"
|
|
53
|
+
}
|
|
54
|
+
}
|