Scene State

class dazpy.DazSceneState(skeleton_poses, camera_transforms, light_transforms, light_extra, follow_targets=None, backup=None)[source]

Bases: object

An in-memory pose checkpoint: figure poses plus camera and light placement.

This is not a full scene snapshot. For anything it does not cover, take a full-scene backup with save_copy(), or pass backup_path to capture() to do both at once.

Captured, for nodes that exist at capture time:

  • every skeleton (figure): bone rotations, morph values and the figure node’s own numeric properties (see DazPose);

  • every skeleton’s fit-to (follow) target;

  • every camera: X/Y/Z translate, X/Y/Z rotate and Scale;

  • every light: the same transform channels, plus Flux, Shadow Softness and Spread Angle.

Not captured:

  • materials and surface properties;

  • HDRI / environment and render settings;

  • nodes added or deleted after capture (restore never creates or deletes nodes; missing ones are reported as skipped);

  • props and any other node that is not a skeleton, camera or light;

  • bone translations, keyframes / animation, and any other camera or light property (focal length, color, etc.).

Everything is captured and restored via each property’s raw (pre-ERC) value, so repeated capture/apply cycles are idempotent even for properties driven by DzERCLink controllers (e.g. a “Scale” dial fed by dozens of linked morphs) – see DazPose and raw_value for why this matters.

Skeletons, cameras, and lights are all keyed by their internal name (not display label), since labels are user-editable and not guaranteed unique.

Typical workflow:

from dazpy import DazScene, DazSceneState

scene = DazScene()
checkpoint = DazSceneState.capture(scene)
...  # experimental changes
checkpoint.apply(scene)
classmethod capture(scene, *, backup_path=None)[source]

Capture the current state of every skeleton, camera, and light in scene.

Parameters:
  • scene (DazScene) – The scene to capture.

  • backup_path (str | None) – If given, first write a full-scene backup to this absolute path on the server host via save_copy(), before anything else is captured. Use it before destructive work (deleting nodes, changing materials or render settings), which this checkpoint cannot undo. The save-copy result is kept in backup and reported again by apply(). If the backup fails, the error is raised and nothing is captured.

Returns:

A new DazSceneState.

Return type:

DazSceneState

to_dict()[source]

Return this snapshot as a plain, JSON-serialisable dict.

classmethod from_dict(data)[source]

Reconstruct a snapshot from to_dict()’s output.

apply(scene, *, max_verify_retries=2, verify_tolerance=0.05)[source]

Apply this snapshot’s skeleton poses, camera transforms, and light properties back onto scene in a small, fixed number of HTTP calls.

Restore is best effort. A skeleton, camera or light that no longer exists in the scene (deleted or renamed since capture) is skipped and listed in skipped, and the rest of the checkpoint is still applied. Nothing is recreated: this restores values, not the scene graph. To get deleted nodes back, reload the full-scene backup taken by capture(backup_path=...).

Each skeleton restore is independently verified: after pose.apply_full(skel) returns, a fresh DazPose.capture() is taken and compared against the checkpoint. This guards against apply_full() reporting success for a restore DAZ Studio’s single-threaded main loop only partially executed under contention (see dpi-mxq) – the HTTP call can return normally even though some bone/morph/prop writes never happened. A skeleton whose read-back doesn’t match is retried (re-running apply_full and re-verifying) up to max_verify_retries times before being reported in errors instead of restored, so callers never trust an unverified result.

Parameters:
  • scene (DazScene) – The scene to restore state into.

  • max_verify_retries (int) – How many additional apply_full attempts to make for a skeleton whose read-back doesn’t verify, before giving up on it.

  • verify_tolerance (float) – Per-channel tolerance (degrees for bones, raw value units for morphs/props) allowed between the checkpoint and the read-back before it’s considered a mismatch.

Returns:

A verification report:

{
    "restored": [name, ...],   # applied (skeletons read back and verified)
    "skipped": [               # nodes no longer in the scene
        {"kind": "skeleton" | "camera" | "light" | "follow_target",
         "name": str, "reason": "not_found"},
    ],
    "errors": [message, ...],  # every problem, skips included
    "complete": bool,          # True only if nothing was skipped or failed
    "backup": dict | None,     # save_copy() result from capture(backup_path=...)
}

Each skipped node also has a line in errors, so a caller that treats any errors entry as a failed restore stays safe. A follow_target skip means the skeleton was restored but the figure it was fitted to is gone, so the fit was not restored.

Return type:

dict