Add Brokkr sync organ contract and editor UX
This commit is contained in:
parent
082579106f
commit
f07ccef598
13 changed files with 944 additions and 5 deletions
11
README.md
11
README.md
|
|
@ -44,6 +44,17 @@ cargo run -p brokkr-daemon -- provider
|
|||
The first smoke prints the typed provider advertisement. That is deliberately
|
||||
small: discovery shape first, live sockets second.
|
||||
|
||||
## Sync Contract
|
||||
|
||||
```powershell
|
||||
cargo run -p brokkr-daemon -- sync-contract
|
||||
```
|
||||
|
||||
The sync contract advertises Brokkr-owned sessions, object bindings, sync vars,
|
||||
timeline bindings, and receipts. Unity and Blender editor plugins publish those
|
||||
documents through CultMesh so a daemon sync loop can translate them into
|
||||
host-owned command intents without stealing scene truth.
|
||||
|
||||
## Unity Smoke
|
||||
|
||||
```powershell
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ struct ProviderAdvertisement {
|
|||
transports: Vec<Transport>,
|
||||
tool_surfaces: Vec<ToolSurface>,
|
||||
mirror_documents: Vec<MirrorDocument>,
|
||||
sync_organ: SyncOrgan,
|
||||
realtime_routes: Vec<RealtimeRoute>,
|
||||
eve_surfaces: Vec<EveSurface>,
|
||||
command_policy: CommandPolicy,
|
||||
|
|
@ -65,6 +66,26 @@ struct MirrorDocument {
|
|||
record_hint: &'static str,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct SyncOrgan {
|
||||
id: &'static str,
|
||||
owner: &'static str,
|
||||
role: &'static str,
|
||||
documents: Vec<SyncDocument>,
|
||||
sync_var_kinds: Vec<&'static str>,
|
||||
policies: Vec<&'static str>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct SyncDocument {
|
||||
name: &'static str,
|
||||
schema: &'static str,
|
||||
owner: &'static str,
|
||||
record_hint: &'static str,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct RealtimeRoute {
|
||||
|
|
@ -102,8 +123,9 @@ fn main() -> Result<()> {
|
|||
|
||||
match command.as_str() {
|
||||
"provider" | "smoke" => print_provider(),
|
||||
"sync-contract" => print_sync_contract(),
|
||||
_ => {
|
||||
eprintln!("usage: brokkr-daemon [provider|smoke]");
|
||||
eprintln!("usage: brokkr-daemon [provider|smoke|sync-contract]");
|
||||
std::process::exit(2);
|
||||
}
|
||||
}
|
||||
|
|
@ -117,6 +139,11 @@ fn print_provider() -> Result<()> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn print_sync_contract() -> Result<()> {
|
||||
println!("{}", serde_json::to_string_pretty(&build_sync_organ())?);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn build_provider_advertisement() -> ProviderAdvertisement {
|
||||
ProviderAdvertisement {
|
||||
schema: PROVIDER_SCHEMA,
|
||||
|
|
@ -157,6 +184,10 @@ fn build_provider_advertisement() -> ProviderAdvertisement {
|
|||
"gameobject.create",
|
||||
"component.attach",
|
||||
"component.property.write",
|
||||
"sync.session.publish",
|
||||
"sync.object.bind",
|
||||
"sync.var.publish",
|
||||
"sync.timeline.bind",
|
||||
"command.receipt.publish",
|
||||
"eve.gui.publish",
|
||||
"eve.tui.publish",
|
||||
|
|
@ -184,6 +215,10 @@ fn build_provider_advertisement() -> ProviderAdvertisement {
|
|||
"material.assign",
|
||||
"selection.read",
|
||||
"selection.write",
|
||||
"sync.session.publish",
|
||||
"sync.object.bind",
|
||||
"sync.var.publish",
|
||||
"sync.timeline.bind",
|
||||
"command.receipt.publish",
|
||||
"eve.gui.publish",
|
||||
"eve.tui.publish",
|
||||
|
|
@ -245,7 +280,38 @@ fn build_provider_advertisement() -> ProviderAdvertisement {
|
|||
owner: "brokkr.blender_editor",
|
||||
record_hint: "blender/receipts/{commandId}",
|
||||
},
|
||||
MirrorDocument {
|
||||
name: "Brokkr sync session",
|
||||
schema: "brokkr.sync.session.v0",
|
||||
owner: PROVIDER_ID,
|
||||
record_hint: "sync/sessions/{sessionId}",
|
||||
},
|
||||
MirrorDocument {
|
||||
name: "Brokkr object binding",
|
||||
schema: "brokkr.sync.object_binding.v0",
|
||||
owner: PROVIDER_ID,
|
||||
record_hint: "sync/bindings/objects/{bindingId}",
|
||||
},
|
||||
MirrorDocument {
|
||||
name: "Brokkr sync var",
|
||||
schema: "brokkr.sync.var.v0",
|
||||
owner: PROVIDER_ID,
|
||||
record_hint: "sync/vars/{syncVarId}",
|
||||
},
|
||||
MirrorDocument {
|
||||
name: "Brokkr timeline binding",
|
||||
schema: "brokkr.sync.timeline_binding.v0",
|
||||
owner: PROVIDER_ID,
|
||||
record_hint: "sync/bindings/timelines/{bindingId}",
|
||||
},
|
||||
MirrorDocument {
|
||||
name: "Brokkr sync receipt",
|
||||
schema: "brokkr.sync.receipt.v0",
|
||||
owner: PROVIDER_ID,
|
||||
record_hint: "sync/receipts/{receiptId}",
|
||||
},
|
||||
],
|
||||
sync_organ: build_sync_organ(),
|
||||
realtime_routes: build_unity_quest_routes(),
|
||||
eve_surfaces: vec![
|
||||
EveSurface {
|
||||
|
|
@ -274,6 +340,64 @@ fn build_provider_advertisement() -> ProviderAdvertisement {
|
|||
}
|
||||
}
|
||||
|
||||
fn build_sync_organ() -> SyncOrgan {
|
||||
SyncOrgan {
|
||||
id: "brokkr.sync_organ.v0",
|
||||
owner: PROVIDER_ID,
|
||||
role: "receipt-driven Unity/Blender correspondence and sync policy",
|
||||
documents: vec![
|
||||
SyncDocument {
|
||||
name: "Sync session",
|
||||
schema: "brokkr.sync.session.v0",
|
||||
owner: PROVIDER_ID,
|
||||
record_hint: "sync/sessions/{sessionId}",
|
||||
},
|
||||
SyncDocument {
|
||||
name: "Object binding",
|
||||
schema: "brokkr.sync.object_binding.v0",
|
||||
owner: PROVIDER_ID,
|
||||
record_hint: "sync/bindings/objects/{bindingId}",
|
||||
},
|
||||
SyncDocument {
|
||||
name: "Sync variable",
|
||||
schema: "brokkr.sync.var.v0",
|
||||
owner: PROVIDER_ID,
|
||||
record_hint: "sync/vars/{syncVarId}",
|
||||
},
|
||||
SyncDocument {
|
||||
name: "Timeline binding",
|
||||
schema: "brokkr.sync.timeline_binding.v0",
|
||||
owner: PROVIDER_ID,
|
||||
record_hint: "sync/bindings/timelines/{bindingId}",
|
||||
},
|
||||
SyncDocument {
|
||||
name: "Sync receipt",
|
||||
schema: "brokkr.sync.receipt.v0",
|
||||
owner: PROVIDER_ID,
|
||||
record_hint: "sync/receipts/{receiptId}",
|
||||
},
|
||||
],
|
||||
sync_var_kinds: vec![
|
||||
"transform",
|
||||
"active-state",
|
||||
"material",
|
||||
"component-property",
|
||||
"custom-property",
|
||||
"timeline-frame",
|
||||
"timeline-time",
|
||||
"animation-clip",
|
||||
"camera-lens",
|
||||
"cinemachine-virtual-camera",
|
||||
],
|
||||
policies: vec![
|
||||
"Editor hosts own mutations; sync records only declare correspondence and desired lanes.",
|
||||
"Sync writes become real only after host command receipts confirm accepted mutations.",
|
||||
"Manual, UI-triggered, and programmatic sync actions use the same sync documents.",
|
||||
"Timeline bindings carry frame/time authority explicitly so Blender animation and Unity Cinemachine can share a clock without stealing editor ownership.",
|
||||
],
|
||||
}
|
||||
}
|
||||
|
||||
fn build_unity_quest_routes() -> Vec<RealtimeRoute> {
|
||||
vec![
|
||||
RealtimeRoute {
|
||||
|
|
@ -395,4 +519,46 @@ mod tests {
|
|||
"blender/receipts/{commandId}"
|
||||
)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn provider_advertises_sync_organ_documents_and_timeline_vars() {
|
||||
let provider = build_provider_advertisement();
|
||||
let sync_documents: Vec<_> = provider
|
||||
.sync_organ
|
||||
.documents
|
||||
.iter()
|
||||
.map(|document| (document.schema, document.record_hint))
|
||||
.collect();
|
||||
let mirror_documents: Vec<_> = provider
|
||||
.mirror_documents
|
||||
.iter()
|
||||
.map(|document| (document.schema, document.owner))
|
||||
.collect();
|
||||
|
||||
assert_eq!(provider.sync_organ.owner, PROVIDER_ID);
|
||||
assert!(sync_documents.contains(&("brokkr.sync.session.v0", "sync/sessions/{sessionId}")));
|
||||
assert!(sync_documents.contains(&(
|
||||
"brokkr.sync.object_binding.v0",
|
||||
"sync/bindings/objects/{bindingId}"
|
||||
)));
|
||||
assert!(sync_documents.contains(&("brokkr.sync.var.v0", "sync/vars/{syncVarId}")));
|
||||
assert!(sync_documents.contains(&(
|
||||
"brokkr.sync.timeline_binding.v0",
|
||||
"sync/bindings/timelines/{bindingId}"
|
||||
)));
|
||||
assert!(sync_documents.contains(&("brokkr.sync.receipt.v0", "sync/receipts/{receiptId}")));
|
||||
assert!(mirror_documents.contains(&("brokkr.sync.var.v0", PROVIDER_ID)));
|
||||
assert!(
|
||||
provider
|
||||
.sync_organ
|
||||
.sync_var_kinds
|
||||
.contains(&"timeline-frame")
|
||||
);
|
||||
assert!(
|
||||
provider
|
||||
.sync_organ
|
||||
.sync_var_kinds
|
||||
.contains(&"cinemachine-virtual-camera")
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,8 +7,9 @@ with Unity and Blender plugin surfaces.
|
|||
|
||||
## Current Mechanism
|
||||
|
||||
Brokkr is a provider identity and editor-adapter contract. The Rust daemon emits
|
||||
the discovery document for Odin and the Verse. It does not own Unity scene
|
||||
Brokkr is a provider identity, editor-adapter contract, and sync organ contract.
|
||||
The Rust daemon emits the discovery document for Odin and the Verse. It owns
|
||||
sync correspondence and policy documents; it does not own Unity or Blender scene
|
||||
truth, command queues, or dashboard state.
|
||||
|
||||
The Unity package opens a durable CultMesh node backed by a CultCache store at
|
||||
|
|
@ -26,6 +27,12 @@ probes. The add-on can serve the node through `CultMesh.serve_node(...)` so
|
|||
external CultNet/CultMesh clients can request schema catalogs, snapshots, shard
|
||||
logs, and raw document mutations.
|
||||
|
||||
The sync organ owns `brokkr.sync.*` documents: sessions, object bindings, sync
|
||||
vars, timeline bindings, and receipts. Unity and Blender plugins can publish
|
||||
those records from editor UI. The daemon contract makes the correspondence
|
||||
inspectable before a later active sync loop translates sync records into host
|
||||
command intents.
|
||||
|
||||
## Invariants
|
||||
|
||||
- Editor hosts keep editor truth. Brokkr never becomes the canonical scene,
|
||||
|
|
@ -34,6 +41,8 @@ logs, and raw document mutations.
|
|||
watch streams, and Verse visibility.
|
||||
- Brokkr owns provider identity, mirror schema advertisement, and discovery
|
||||
metadata.
|
||||
- Brokkr owns sync correspondence and policy records. Editor hosts still own
|
||||
scene mutation.
|
||||
- Unity owns Unity editor mutations. A command intent is not truth until Unity
|
||||
publishes a receipt and refreshed mirror state.
|
||||
- Eve/CultUI surfaces are typed projections over the mirror, not renderer-owned
|
||||
|
|
@ -75,6 +84,11 @@ Outputs:
|
|||
- `brokkr.blender.host_snapshot.v0`
|
||||
- `brokkr.blender.command_intent.v0`
|
||||
- `brokkr.blender.command_receipt.v0`
|
||||
- `brokkr.sync.session.v0`
|
||||
- `brokkr.sync.object_binding.v0`
|
||||
- `brokkr.sync.var.v0`
|
||||
- `brokkr.sync.timeline_binding.v0`
|
||||
- `brokkr.sync.receipt.v0`
|
||||
- Eve/CultUI surface documents for host status, selection, assets, scene/object
|
||||
trees, component state, command affordances, and receipt history.
|
||||
|
||||
|
|
@ -83,6 +97,8 @@ Derived State:
|
|||
- Unity package settings are adapter configuration, not Verse authority.
|
||||
- Blender add-on preferences are adapter configuration, not Verse authority.
|
||||
- Blender JSON debug exports are inspection/import probes, not mirror authority.
|
||||
- Unity and Blender sync UI fields are command/edit affordances; the
|
||||
`brokkr.sync.*` documents are the shared sync policy surface.
|
||||
- Editor selection and scene summaries are observations until command receipts
|
||||
confirm an accepted mutation.
|
||||
|
||||
|
|
|
|||
|
|
@ -40,6 +40,30 @@ Primary Eve surface id: `brokkr.eve.tool_broker.v0`
|
|||
- `brokkr.blender.host_snapshot.v0` at `blender/host/current`
|
||||
- `brokkr.blender.command_intent.v0` at `blender/commands/{commandId}`
|
||||
- `brokkr.blender.command_receipt.v0` at `blender/receipts/{commandId}`
|
||||
- `brokkr.sync.session.v0` at `sync/sessions/{sessionId}`
|
||||
- `brokkr.sync.object_binding.v0` at `sync/bindings/objects/{bindingId}`
|
||||
- `brokkr.sync.var.v0` at `sync/vars/{syncVarId}`
|
||||
- `brokkr.sync.timeline_binding.v0` at `sync/bindings/timelines/{bindingId}`
|
||||
- `brokkr.sync.receipt.v0` at `sync/receipts/{receiptId}`
|
||||
|
||||
## Sync Organ
|
||||
|
||||
Brokkr owns sync correspondence and policy documents. Editor hosts still own
|
||||
scene mutation. A sync record can request or describe a lane, but it is not real
|
||||
editor state until Unity or Blender publishes accepted command receipts and a
|
||||
fresh host snapshot.
|
||||
|
||||
Primary sync documents:
|
||||
|
||||
- `brokkr.sync.session.v0`: shared sync session and mode.
|
||||
- `brokkr.sync.object_binding.v0`: Unity GameObject to Blender object/collection
|
||||
correspondence.
|
||||
- `brokkr.sync.var.v0`: per-lane sync options such as transform, material,
|
||||
component property, custom property, timeline frame, camera lens, or
|
||||
Cinemachine virtual camera.
|
||||
- `brokkr.sync.timeline_binding.v0`: Blender scene/action timeline to Unity
|
||||
Timeline/Cinemachine correspondence.
|
||||
- `brokkr.sync.receipt.v0`: daemon sync pass receipts.
|
||||
|
||||
## Unity Command Actions
|
||||
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ class BrokkrPreferences(bpy.types.AddonPreferences):
|
|||
name="Debug Export Root",
|
||||
subtype="DIR_PATH",
|
||||
default=DEFAULT_DEBUG_MIRROR_ROOT,
|
||||
description="Optional JSON debug export/import root; CultCache remains the mirror owner",
|
||||
description="Optional JSON debug export/import root; CultMesh remains the mirror owner",
|
||||
)
|
||||
|
||||
auto_capture: bpy.props.BoolProperty(
|
||||
|
|
@ -94,6 +94,78 @@ class BrokkrPreferences(bpy.types.AddonPreferences):
|
|||
description="Maximum encoded snapshot response size",
|
||||
)
|
||||
|
||||
sync_session_id: bpy.props.StringProperty(
|
||||
name="Sync Session",
|
||||
default="default",
|
||||
description="Brokkr sync session id shared with Unity",
|
||||
)
|
||||
|
||||
sync_display_name: bpy.props.StringProperty(
|
||||
name="Sync Display Name",
|
||||
default="Brokkr Editor Sync",
|
||||
description="Human-readable Brokkr sync session label",
|
||||
)
|
||||
|
||||
unity_object_id: bpy.props.StringProperty(
|
||||
name="Unity Object Id",
|
||||
default="",
|
||||
description="Unity GlobalObjectId for the object bound to the active Blender object",
|
||||
)
|
||||
|
||||
unity_object_path: bpy.props.StringProperty(
|
||||
name="Unity Object Path",
|
||||
default="",
|
||||
description="Unity hierarchy path for the bound object",
|
||||
)
|
||||
|
||||
sync_transform: bpy.props.BoolProperty(
|
||||
name="Sync Transform",
|
||||
default=True,
|
||||
description="Synchronize object transforms",
|
||||
)
|
||||
|
||||
sync_material: bpy.props.BoolProperty(
|
||||
name="Sync Material",
|
||||
default=True,
|
||||
description="Synchronize material assignment",
|
||||
)
|
||||
|
||||
sync_custom_properties: bpy.props.BoolProperty(
|
||||
name="Sync Custom Properties",
|
||||
default=False,
|
||||
description="Synchronize Blender custom properties as sync vars",
|
||||
)
|
||||
|
||||
unity_timeline_object_id: bpy.props.StringProperty(
|
||||
name="Unity Timeline Object",
|
||||
default="",
|
||||
description="Unity object id that owns the timeline binding",
|
||||
)
|
||||
|
||||
unity_cinemachine_object_id: bpy.props.StringProperty(
|
||||
name="Unity Cinemachine Object",
|
||||
default="",
|
||||
description="Unity Cinemachine object id receiving camera sync",
|
||||
)
|
||||
|
||||
blender_action_name: bpy.props.StringProperty(
|
||||
name="Blender Action",
|
||||
default="",
|
||||
description="Blender action name for timeline sync; blank uses the active object's action",
|
||||
)
|
||||
|
||||
sync_timeline_frame: bpy.props.BoolProperty(
|
||||
name="Sync Timeline Frame",
|
||||
default=True,
|
||||
description="Synchronize Blender scene frame/time into the Brokkr timeline sync var",
|
||||
)
|
||||
|
||||
sync_cinemachine_camera: bpy.props.BoolProperty(
|
||||
name="Sync Cinemachine Camera",
|
||||
default=True,
|
||||
description="Synchronize Blender camera animation into Unity Cinemachine lanes",
|
||||
)
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
layout.prop(self, "broker_uri")
|
||||
|
|
@ -105,6 +177,18 @@ class BrokkrPreferences(bpy.types.AddonPreferences):
|
|||
layout.prop(self, "serve_port")
|
||||
layout.prop(self, "max_snapshot_documents")
|
||||
layout.prop(self, "max_snapshot_bytes")
|
||||
layout.prop(self, "sync_session_id")
|
||||
layout.prop(self, "sync_display_name")
|
||||
layout.prop(self, "unity_object_id")
|
||||
layout.prop(self, "unity_object_path")
|
||||
layout.prop(self, "sync_transform")
|
||||
layout.prop(self, "sync_material")
|
||||
layout.prop(self, "sync_custom_properties")
|
||||
layout.prop(self, "unity_timeline_object_id")
|
||||
layout.prop(self, "unity_cinemachine_object_id")
|
||||
layout.prop(self, "blender_action_name")
|
||||
layout.prop(self, "sync_timeline_frame")
|
||||
layout.prop(self, "sync_cinemachine_camera")
|
||||
|
||||
|
||||
class BROKKR_PT_status(bpy.types.Panel):
|
||||
|
|
@ -134,6 +218,10 @@ class BROKKR_PT_status(bpy.types.Panel):
|
|||
server_row.operator("brokkr.start_server", icon="NETWORK_DRIVE")
|
||||
server_row.operator("brokkr.stop_server", icon="CANCEL")
|
||||
|
||||
sync_row = layout.row(align=True)
|
||||
sync_row.operator("brokkr.publish_object_sync", icon="LINKED")
|
||||
sync_row.operator("brokkr.publish_timeline_sync", icon="TIME")
|
||||
|
||||
if adapter.last_snapshot:
|
||||
layout.separator()
|
||||
layout.label(text=f"Objects: {adapter.last_snapshot.get('objectCount', 0)}")
|
||||
|
|
@ -210,6 +298,52 @@ class BROKKR_OT_stop_server(bpy.types.Operator):
|
|||
return {"FINISHED"}
|
||||
|
||||
|
||||
class BROKKR_OT_publish_object_sync(bpy.types.Operator):
|
||||
bl_idname = "brokkr.publish_object_sync"
|
||||
bl_label = "Object Sync"
|
||||
bl_description = "Publish a Brokkr object binding for the active Blender object"
|
||||
|
||||
def execute(self, context):
|
||||
prefs = context.preferences.addons[__name__].preferences
|
||||
binding = target().publish_object_sync(
|
||||
context,
|
||||
prefs.cultmesh_cache_path,
|
||||
prefs.cultlib_py_src,
|
||||
prefs.sync_session_id,
|
||||
prefs.sync_display_name,
|
||||
prefs.unity_object_id,
|
||||
prefs.unity_object_path,
|
||||
prefs.sync_transform,
|
||||
prefs.sync_material,
|
||||
prefs.sync_custom_properties,
|
||||
)
|
||||
self.report({"INFO"}, f"Brokkr object sync: {binding['displayName']}")
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
class BROKKR_OT_publish_timeline_sync(bpy.types.Operator):
|
||||
bl_idname = "brokkr.publish_timeline_sync"
|
||||
bl_label = "Timeline Sync"
|
||||
bl_description = "Publish a Brokkr timeline binding for Blender animation and Unity Cinemachine"
|
||||
|
||||
def execute(self, context):
|
||||
prefs = context.preferences.addons[__name__].preferences
|
||||
binding = target().publish_timeline_sync(
|
||||
context,
|
||||
prefs.cultmesh_cache_path,
|
||||
prefs.cultlib_py_src,
|
||||
prefs.sync_session_id,
|
||||
prefs.sync_display_name,
|
||||
prefs.unity_timeline_object_id,
|
||||
prefs.unity_cinemachine_object_id,
|
||||
prefs.blender_action_name,
|
||||
prefs.sync_timeline_frame,
|
||||
prefs.sync_cinemachine_camera,
|
||||
)
|
||||
self.report({"INFO"}, f"Brokkr timeline sync: {binding['displayName']}")
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
def _auto_capture(scene, depsgraph):
|
||||
context = bpy.context
|
||||
prefs = context.preferences.addons.get(__name__)
|
||||
|
|
@ -230,6 +364,8 @@ classes = (
|
|||
BROKKR_OT_drain_commands,
|
||||
BROKKR_OT_start_server,
|
||||
BROKKR_OT_stop_server,
|
||||
BROKKR_OT_publish_object_sync,
|
||||
BROKKR_OT_publish_timeline_sync,
|
||||
)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -19,6 +19,11 @@ DEFAULT_DEBUG_MIRROR_ROOT = "//.brokkr/blender-editor-debug"
|
|||
HOST_SNAPSHOT_SCHEMA = "brokkr.blender.host_snapshot.v0"
|
||||
COMMAND_INTENT_SCHEMA = "brokkr.blender.command_intent.v0"
|
||||
COMMAND_RECEIPT_SCHEMA = "brokkr.blender.command_receipt.v0"
|
||||
SYNC_SESSION_SCHEMA = "brokkr.sync.session.v0"
|
||||
SYNC_OBJECT_BINDING_SCHEMA = "brokkr.sync.object_binding.v0"
|
||||
SYNC_VAR_SCHEMA = "brokkr.sync.var.v0"
|
||||
SYNC_TIMELINE_BINDING_SCHEMA = "brokkr.sync.timeline_binding.v0"
|
||||
SYNC_RECEIPT_SCHEMA = "brokkr.sync.receipt.v0"
|
||||
|
||||
CAPABILITIES = (
|
||||
"cultcache.mirror.publish",
|
||||
|
|
@ -110,6 +115,95 @@ class BrokkrBlenderTarget:
|
|||
self._write_debug_document(debug_mirror_root, f"blender/receipts/{command_id}.json", receipt)
|
||||
self.last_receipt = receipt
|
||||
|
||||
def publish_object_sync(
|
||||
self,
|
||||
context: Any,
|
||||
cache_path: str,
|
||||
cultlib_py_src: str,
|
||||
session_id: str,
|
||||
display_name: str,
|
||||
unity_object_id: str,
|
||||
unity_path: str,
|
||||
sync_transform: bool,
|
||||
sync_material: bool,
|
||||
sync_custom_properties: bool,
|
||||
) -> dict[str, Any]:
|
||||
obj = context.active_object
|
||||
if obj is None:
|
||||
raise RuntimeError("Select a Blender object before publishing object sync.")
|
||||
|
||||
now = _now()
|
||||
node, documents = self._open_node(cache_path, cultlib_py_src)
|
||||
normalized_session_id = session_id or "default"
|
||||
binding_id = _stable_id("object", normalized_session_id, obj.name, unity_object_id)
|
||||
session = _sync_session(normalized_session_id, display_name, now)
|
||||
binding = {
|
||||
"schema": SYNC_OBJECT_BINDING_SCHEMA,
|
||||
"bindingId": binding_id,
|
||||
"sessionId": normalized_session_id,
|
||||
"displayName": obj.name,
|
||||
"unityObjectId": unity_object_id,
|
||||
"unityPath": unity_path,
|
||||
"blenderObjectName": obj.name,
|
||||
"blenderCollectionName": obj.users_collection[0].name if obj.users_collection else "",
|
||||
"enabled": True,
|
||||
"authority": "blender-to-unity",
|
||||
"updatedAt": now,
|
||||
}
|
||||
|
||||
node.database.put(documents["sync_session"], f"sync/sessions/{normalized_session_id}", session)
|
||||
node.database.put(documents["sync_object_binding"], f"sync/bindings/objects/{binding_id}", binding)
|
||||
self._put_sync_var(node, documents, normalized_session_id, binding_id, "transform", "Transform", "Transform", "location,rotationEuler,scale", "blender-to-unity", sync_transform, "linear", now)
|
||||
self._put_sync_var(node, documents, normalized_session_id, binding_id, "material", "Material", "Renderer.m_Materials", "materials", "blender-to-unity", sync_material, "step", now)
|
||||
self._put_sync_var(node, documents, normalized_session_id, binding_id, "custom-property", "Custom Properties", "Component.Property", "customProperties", "blender-to-unity", sync_custom_properties, "step", now)
|
||||
return binding
|
||||
|
||||
def publish_timeline_sync(
|
||||
self,
|
||||
context: Any,
|
||||
cache_path: str,
|
||||
cultlib_py_src: str,
|
||||
session_id: str,
|
||||
display_name: str,
|
||||
unity_timeline_object_id: str,
|
||||
unity_cinemachine_object_id: str,
|
||||
blender_action_name: str,
|
||||
sync_frame: bool,
|
||||
sync_camera: bool,
|
||||
) -> dict[str, Any]:
|
||||
scene = context.scene
|
||||
if scene is None:
|
||||
raise RuntimeError("Open a Blender scene before publishing timeline sync.")
|
||||
|
||||
now = _now()
|
||||
node, documents = self._open_node(cache_path, cultlib_py_src)
|
||||
normalized_session_id = session_id or "default"
|
||||
action_name = blender_action_name or _active_action_name(context)
|
||||
binding_id = _stable_id("timeline", normalized_session_id, scene.name, action_name, unity_timeline_object_id)
|
||||
session = _sync_session(normalized_session_id, display_name, now)
|
||||
binding = {
|
||||
"schema": SYNC_TIMELINE_BINDING_SCHEMA,
|
||||
"bindingId": binding_id,
|
||||
"sessionId": normalized_session_id,
|
||||
"displayName": action_name or scene.name,
|
||||
"unityTimelineObjectId": unity_timeline_object_id,
|
||||
"unityCinemachineObjectId": unity_cinemachine_object_id,
|
||||
"blenderSceneName": scene.name,
|
||||
"blenderActionName": action_name,
|
||||
"clockAuthority": "blender",
|
||||
"frameRate": float(scene.render.fps),
|
||||
"syncFrame": bool(sync_frame),
|
||||
"syncCamera": bool(sync_camera),
|
||||
"enabled": bool(sync_frame or sync_camera),
|
||||
"updatedAt": now,
|
||||
}
|
||||
|
||||
node.database.put(documents["sync_session"], f"sync/sessions/{normalized_session_id}", session)
|
||||
node.database.put(documents["sync_timeline_binding"], f"sync/bindings/timelines/{binding_id}", binding)
|
||||
self._put_sync_var(node, documents, normalized_session_id, binding_id, "timeline-frame", "Timeline Frame", "Timeline.time", "scene.frame_current", "blender-to-unity", sync_frame, "linear", now)
|
||||
self._put_sync_var(node, documents, normalized_session_id, binding_id, "cinemachine-virtual-camera", "Cinemachine Camera", "CinemachineVirtualCamera", "camera", "blender-to-unity", sync_camera, "linear", now)
|
||||
return binding
|
||||
|
||||
def start_server(
|
||||
self,
|
||||
cache_path: str,
|
||||
|
|
@ -404,6 +498,11 @@ class BrokkrBlenderTarget:
|
|||
"host_snapshot": cultcache.define_document_type(HOST_SNAPSHOT_SCHEMA),
|
||||
"command_intent": cultcache.define_document_type(COMMAND_INTENT_SCHEMA),
|
||||
"command_receipt": cultcache.define_document_type(COMMAND_RECEIPT_SCHEMA),
|
||||
"sync_session": cultcache.define_document_type(SYNC_SESSION_SCHEMA),
|
||||
"sync_object_binding": cultcache.define_document_type(SYNC_OBJECT_BINDING_SCHEMA),
|
||||
"sync_var": cultcache.define_document_type(SYNC_VAR_SCHEMA),
|
||||
"sync_timeline_binding": cultcache.define_document_type(SYNC_TIMELINE_BINDING_SCHEMA),
|
||||
"sync_receipt": cultcache.define_document_type(SYNC_RECEIPT_SCHEMA),
|
||||
}
|
||||
node = cultmesh.CultMesh.start_node(path, runtime_id=runtime_id)
|
||||
for document in documents.values():
|
||||
|
|
@ -432,6 +531,37 @@ class BrokkrBlenderTarget:
|
|||
with path.open("w", encoding="utf-8") as handle:
|
||||
json.dump(document, handle, indent=2, sort_keys=True)
|
||||
|
||||
def _put_sync_var(
|
||||
self,
|
||||
node: Any,
|
||||
documents: dict[str, Any],
|
||||
session_id: str,
|
||||
binding_id: str,
|
||||
kind: str,
|
||||
display_name: str,
|
||||
unity_property_path: str,
|
||||
blender_property_path: str,
|
||||
authority: str,
|
||||
enabled: bool,
|
||||
interpolation: str,
|
||||
updated_at: str,
|
||||
) -> None:
|
||||
sync_var_id = _stable_id("var", session_id, binding_id, kind)
|
||||
node.database.put(documents["sync_var"], f"sync/vars/{sync_var_id}", {
|
||||
"schema": SYNC_VAR_SCHEMA,
|
||||
"syncVarId": sync_var_id,
|
||||
"sessionId": session_id,
|
||||
"bindingId": binding_id,
|
||||
"displayName": display_name,
|
||||
"kind": kind,
|
||||
"unityPropertyPath": unity_property_path,
|
||||
"blenderPropertyPath": blender_property_path,
|
||||
"authority": authority,
|
||||
"enabled": bool(enabled),
|
||||
"interpolation": interpolation,
|
||||
"updatedAt": updated_at,
|
||||
})
|
||||
|
||||
|
||||
def _load_cultmesh(cultlib_py_src: str) -> tuple[Any, Any]:
|
||||
source = Path(cultlib_py_src or DEFAULT_CULTLIB_PY_SRC)
|
||||
|
|
@ -477,3 +607,29 @@ def _jsonable(value: Any) -> Any:
|
|||
if isinstance(value, dict):
|
||||
return {str(key): _jsonable(item) for key, item in value.items()}
|
||||
return str(value)
|
||||
|
||||
|
||||
def _sync_session(session_id: str, display_name: str, updated_at: str) -> dict[str, Any]:
|
||||
return {
|
||||
"schema": SYNC_SESSION_SCHEMA,
|
||||
"sessionId": session_id,
|
||||
"displayName": display_name or "Brokkr Editor Sync",
|
||||
"owner": "brokkr.creative_tool_broker",
|
||||
"unityProviderId": "brokkr.unity_editor",
|
||||
"blenderProviderId": PROVIDER_ID,
|
||||
"mode": "manual",
|
||||
"enabled": True,
|
||||
"createdAt": updated_at,
|
||||
"updatedAt": updated_at,
|
||||
}
|
||||
|
||||
|
||||
def _stable_id(*parts: str) -> str:
|
||||
return ":".join(str(part or "").replace(" ", "_").replace("/", "_").replace("\\", "_") for part in parts)
|
||||
|
||||
|
||||
def _active_action_name(context: Any) -> str:
|
||||
obj = context.active_object
|
||||
if obj is not None and obj.animation_data and obj.animation_data.action:
|
||||
return obj.animation_data.action.name
|
||||
return ""
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ a stable endpoint. The panel reports the active `cultnet://host:port` endpoint
|
|||
after `Start Server`.
|
||||
|
||||
`Debug Export Root` may still emit readable JSON probe files under
|
||||
`.brokkr/blender-editor-debug`, but those files are debug/import glue. CultCache
|
||||
`.brokkr/blender-editor-debug`, but those files are debug/import glue. CultMesh
|
||||
owns the mirror state.
|
||||
|
||||
## Local Smoke
|
||||
|
|
@ -44,6 +44,10 @@ owns the mirror state.
|
|||
8. Click `Start Server`.
|
||||
9. Use the reported `cultnet://host:port` endpoint from a CultMesh/CultNet
|
||||
client to read snapshots or write command intents.
|
||||
10. Select a Blender object and click `Object Sync` to publish a
|
||||
`brokkr.sync.object_binding.v0` plus per-lane `brokkr.sync.var.v0` records.
|
||||
11. Click `Timeline Sync` to publish a `brokkr.sync.timeline_binding.v0` for
|
||||
Blender frame/action data and Unity Timeline/Cinemachine lanes.
|
||||
|
||||
Admitted command actions:
|
||||
|
||||
|
|
|
|||
|
|
@ -74,6 +74,34 @@ namespace GameCult.Brokkr.Editor
|
|||
await node.FlushAsync(soft: true);
|
||||
}
|
||||
|
||||
internal async Task PublishSyncSessionAsync(BrokkrSyncSession session)
|
||||
{
|
||||
RequireRunning();
|
||||
await node.Database.PutAsync(new CultRecordKey($"sync/sessions/{session.sessionId}"), session);
|
||||
await node.FlushAsync(soft: true);
|
||||
}
|
||||
|
||||
internal async Task PublishSyncObjectBindingAsync(BrokkrSyncObjectBinding binding)
|
||||
{
|
||||
RequireRunning();
|
||||
await node.Database.PutAsync(new CultRecordKey($"sync/bindings/objects/{binding.bindingId}"), binding);
|
||||
await node.FlushAsync(soft: true);
|
||||
}
|
||||
|
||||
internal async Task PublishSyncVarAsync(BrokkrSyncVar syncVar)
|
||||
{
|
||||
RequireRunning();
|
||||
await node.Database.PutAsync(new CultRecordKey($"sync/vars/{syncVar.syncVarId}"), syncVar);
|
||||
await node.FlushAsync(soft: true);
|
||||
}
|
||||
|
||||
internal async Task PublishTimelineBindingAsync(BrokkrSyncTimelineBinding binding)
|
||||
{
|
||||
RequireRunning();
|
||||
await node.Database.PutAsync(new CultRecordKey($"sync/bindings/timelines/{binding.bindingId}"), binding);
|
||||
await node.FlushAsync(soft: true);
|
||||
}
|
||||
|
||||
internal bool TryDequeueCommand(out BrokkrUnityCommand command)
|
||||
{
|
||||
if (commandQueue.Count > 0)
|
||||
|
|
|
|||
|
|
@ -31,5 +31,53 @@ namespace GameCult.Brokkr.Editor
|
|||
get => EditorPrefs.GetString("GameCult.Brokkr.CultMeshCachePath", BrokkrCultMeshMirror.DefaultCachePath());
|
||||
set => EditorPrefs.SetString("GameCult.Brokkr.CultMeshCachePath", value);
|
||||
}
|
||||
|
||||
internal static string SyncSessionId
|
||||
{
|
||||
get => EditorPrefs.GetString("GameCult.Brokkr.SyncSessionId", "default");
|
||||
set => EditorPrefs.SetString("GameCult.Brokkr.SyncSessionId", value);
|
||||
}
|
||||
|
||||
internal static string SyncDisplayName
|
||||
{
|
||||
get => EditorPrefs.GetString("GameCult.Brokkr.SyncDisplayName", "Brokkr Editor Sync");
|
||||
set => EditorPrefs.SetString("GameCult.Brokkr.SyncDisplayName", value);
|
||||
}
|
||||
|
||||
internal static string BlenderObjectName
|
||||
{
|
||||
get => EditorPrefs.GetString("GameCult.Brokkr.BlenderObjectName", "");
|
||||
set => EditorPrefs.SetString("GameCult.Brokkr.BlenderObjectName", value);
|
||||
}
|
||||
|
||||
internal static string BlenderCollectionName
|
||||
{
|
||||
get => EditorPrefs.GetString("GameCult.Brokkr.BlenderCollectionName", "");
|
||||
set => EditorPrefs.SetString("GameCult.Brokkr.BlenderCollectionName", value);
|
||||
}
|
||||
|
||||
internal static string BlenderSceneName
|
||||
{
|
||||
get => EditorPrefs.GetString("GameCult.Brokkr.BlenderSceneName", "");
|
||||
set => EditorPrefs.SetString("GameCult.Brokkr.BlenderSceneName", value);
|
||||
}
|
||||
|
||||
internal static string UnityTimelineObjectId
|
||||
{
|
||||
get => EditorPrefs.GetString("GameCult.Brokkr.UnityTimelineObjectId", "");
|
||||
set => EditorPrefs.SetString("GameCult.Brokkr.UnityTimelineObjectId", value);
|
||||
}
|
||||
|
||||
internal static string UnityCinemachineObjectId
|
||||
{
|
||||
get => EditorPrefs.GetString("GameCult.Brokkr.UnityCinemachineObjectId", "");
|
||||
set => EditorPrefs.SetString("GameCult.Brokkr.UnityCinemachineObjectId", value);
|
||||
}
|
||||
|
||||
internal static string BlenderActionName
|
||||
{
|
||||
get => EditorPrefs.GetString("GameCult.Brokkr.BlenderActionName", "");
|
||||
set => EditorPrefs.SetString("GameCult.Brokkr.BlenderActionName", value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,21 @@ namespace GameCult.Brokkr.Editor
|
|||
private MessageType lastMessageType = MessageType.Info;
|
||||
private double nextPollAt;
|
||||
private BrokkrCultMeshMirror mirror;
|
||||
private string syncSessionId = "default";
|
||||
private string syncDisplayName = "Brokkr Editor Sync";
|
||||
private string blenderObjectName = "";
|
||||
private string blenderCollectionName = "";
|
||||
private bool syncObjectEnabled = true;
|
||||
private bool syncTransform = true;
|
||||
private bool syncActiveState = true;
|
||||
private bool syncMaterial;
|
||||
private bool syncTimelineFrame = true;
|
||||
private bool syncCinemachineCamera = true;
|
||||
private float syncTimelineFrameRate = 24.0f;
|
||||
private string unityTimelineObjectId = "";
|
||||
private string unityCinemachineObjectId = "";
|
||||
private string blenderSceneName = "";
|
||||
private string blenderActionName = "";
|
||||
|
||||
[MenuItem("GameCult/Brokkr")]
|
||||
public static void Open()
|
||||
|
|
@ -29,6 +44,14 @@ namespace GameCult.Brokkr.Editor
|
|||
cultMeshCachePath = BrokkrSettings.CultMeshCachePath;
|
||||
autoPublish = BrokkrSettings.AutoPublish;
|
||||
autoPollCommands = BrokkrSettings.AutoPollCommands;
|
||||
syncSessionId = BrokkrSettings.SyncSessionId;
|
||||
syncDisplayName = BrokkrSettings.SyncDisplayName;
|
||||
blenderObjectName = BrokkrSettings.BlenderObjectName;
|
||||
blenderCollectionName = BrokkrSettings.BlenderCollectionName;
|
||||
unityTimelineObjectId = BrokkrSettings.UnityTimelineObjectId;
|
||||
unityCinemachineObjectId = BrokkrSettings.UnityCinemachineObjectId;
|
||||
blenderSceneName = BrokkrSettings.BlenderSceneName;
|
||||
blenderActionName = BrokkrSettings.BlenderActionName;
|
||||
Selection.selectionChanged += Repaint;
|
||||
EditorSceneManagerBridge.SceneDirtied += OnEditorSignal;
|
||||
EditorApplication.playModeStateChanged += OnPlayModeChanged;
|
||||
|
|
@ -60,6 +83,14 @@ namespace GameCult.Brokkr.Editor
|
|||
BrokkrSettings.CultMeshCachePath = cultMeshCachePath;
|
||||
BrokkrSettings.AutoPublish = autoPublish;
|
||||
BrokkrSettings.AutoPollCommands = autoPollCommands;
|
||||
BrokkrSettings.SyncSessionId = syncSessionId;
|
||||
BrokkrSettings.SyncDisplayName = syncDisplayName;
|
||||
BrokkrSettings.BlenderObjectName = blenderObjectName;
|
||||
BrokkrSettings.BlenderCollectionName = blenderCollectionName;
|
||||
BrokkrSettings.UnityTimelineObjectId = unityTimelineObjectId;
|
||||
BrokkrSettings.UnityCinemachineObjectId = unityCinemachineObjectId;
|
||||
BrokkrSettings.BlenderSceneName = blenderSceneName;
|
||||
BrokkrSettings.BlenderActionName = blenderActionName;
|
||||
SetStatus("Settings saved.", MessageType.Info);
|
||||
}
|
||||
|
||||
|
|
@ -104,6 +135,65 @@ namespace GameCult.Brokkr.Editor
|
|||
EditorGUILayout.LabelField("Scene Objects", lastSnapshot.sceneObjects.Length.ToString());
|
||||
EditorGUILayout.LabelField("Selection", string.Join(", ", lastSnapshot.selectedObjectNames));
|
||||
}
|
||||
|
||||
DrawSyncSection();
|
||||
}
|
||||
|
||||
private void DrawSyncSection()
|
||||
{
|
||||
EditorGUILayout.Space();
|
||||
EditorGUILayout.LabelField("Brokkr Sync", EditorStyles.boldLabel);
|
||||
syncSessionId = EditorGUILayout.TextField("Session Id", syncSessionId);
|
||||
syncDisplayName = EditorGUILayout.TextField("Display Name", syncDisplayName);
|
||||
blenderObjectName = EditorGUILayout.TextField("Blender Object", blenderObjectName);
|
||||
blenderCollectionName = EditorGUILayout.TextField("Blender Collection", blenderCollectionName);
|
||||
syncObjectEnabled = EditorGUILayout.Toggle("Enable Object Binding", syncObjectEnabled);
|
||||
syncTransform = EditorGUILayout.Toggle("Sync Transform", syncTransform);
|
||||
syncActiveState = EditorGUILayout.Toggle("Sync Active State", syncActiveState);
|
||||
syncMaterial = EditorGUILayout.Toggle("Sync Material", syncMaterial);
|
||||
|
||||
using (new EditorGUILayout.HorizontalScope())
|
||||
{
|
||||
if (GUILayout.Button("Use Selected Object Name"))
|
||||
{
|
||||
var selected = Selection.activeGameObject;
|
||||
if (selected != null)
|
||||
{
|
||||
blenderObjectName = selected.name;
|
||||
}
|
||||
}
|
||||
|
||||
if (GUILayout.Button("Publish Object Sync"))
|
||||
{
|
||||
PublishSelectedObjectSync();
|
||||
}
|
||||
}
|
||||
|
||||
EditorGUILayout.Space();
|
||||
EditorGUILayout.LabelField("Timeline / Cinemachine", EditorStyles.boldLabel);
|
||||
unityTimelineObjectId = EditorGUILayout.TextField("Unity Timeline Object", unityTimelineObjectId);
|
||||
unityCinemachineObjectId = EditorGUILayout.TextField("Unity Cinemachine Object", unityCinemachineObjectId);
|
||||
blenderSceneName = EditorGUILayout.TextField("Blender Scene", blenderSceneName);
|
||||
blenderActionName = EditorGUILayout.TextField("Blender Action", blenderActionName);
|
||||
syncTimelineFrameRate = EditorGUILayout.FloatField("Frame Rate", syncTimelineFrameRate);
|
||||
syncTimelineFrame = EditorGUILayout.Toggle("Sync Timeline Frame", syncTimelineFrame);
|
||||
syncCinemachineCamera = EditorGUILayout.Toggle("Sync Cinemachine Camera", syncCinemachineCamera);
|
||||
|
||||
if (GUILayout.Button("Publish Timeline Sync"))
|
||||
{
|
||||
PublishTimelineSync();
|
||||
}
|
||||
|
||||
if (GUILayout.Button("Use Selected For Timeline/Cinemachine"))
|
||||
{
|
||||
var selected = Selection.activeGameObject;
|
||||
if (selected != null)
|
||||
{
|
||||
var selectedId = BrokkrUnitySnapshotBuilder.GetObjectId(selected);
|
||||
unityTimelineObjectId = selectedId;
|
||||
unityCinemachineObjectId = selectedId;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void CaptureSnapshot()
|
||||
|
|
@ -172,6 +262,152 @@ namespace GameCult.Brokkr.Editor
|
|||
}
|
||||
}
|
||||
|
||||
private void PublishSelectedObjectSync()
|
||||
{
|
||||
try
|
||||
{
|
||||
RequireMirror();
|
||||
var selected = Selection.activeGameObject;
|
||||
if (selected == null)
|
||||
{
|
||||
throw new InvalidOperationException("Select a Unity GameObject before publishing object sync.");
|
||||
}
|
||||
|
||||
var now = DateTime.UtcNow.ToString("O");
|
||||
var sessionId = NormalizedSyncSessionId();
|
||||
var session = BuildSyncSession(now);
|
||||
var bindingId = StableId("object", sessionId, BrokkrUnitySnapshotBuilder.GetObjectId(selected));
|
||||
var binding = new BrokkrSyncObjectBinding
|
||||
{
|
||||
bindingId = bindingId,
|
||||
sessionId = sessionId,
|
||||
displayName = selected.name,
|
||||
unityObjectId = BrokkrUnitySnapshotBuilder.GetObjectId(selected),
|
||||
unityPath = BuildTransformPath(selected.transform),
|
||||
blenderObjectName = string.IsNullOrWhiteSpace(blenderObjectName) ? selected.name : blenderObjectName,
|
||||
blenderCollectionName = blenderCollectionName,
|
||||
enabled = syncObjectEnabled,
|
||||
authority = "unity-to-blender",
|
||||
updatedAt = now
|
||||
};
|
||||
|
||||
mirror.PublishSyncSessionAsync(session).GetAwaiter().GetResult();
|
||||
mirror.PublishSyncObjectBindingAsync(binding).GetAwaiter().GetResult();
|
||||
PublishSyncVar(bindingId, "transform", "Transform", "m_LocalPosition,m_LocalRotation,m_LocalScale", "location,rotationEuler,scale", syncTransform, "linear", now);
|
||||
PublishSyncVar(bindingId, "active-state", "Active State", "m_IsActive", "visible", syncActiveState, "step", now);
|
||||
PublishSyncVar(bindingId, "material", "Material", "Renderer.m_Materials", "materials", syncMaterial, "step", now);
|
||||
SetStatus($"Published Brokkr object sync binding: {binding.displayName}", MessageType.Info);
|
||||
}
|
||||
catch (Exception error)
|
||||
{
|
||||
SetStatus(error.Message, MessageType.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void PublishTimelineSync()
|
||||
{
|
||||
try
|
||||
{
|
||||
RequireMirror();
|
||||
var now = DateTime.UtcNow.ToString("O");
|
||||
var selected = Selection.activeGameObject;
|
||||
var selectedId = selected != null ? BrokkrUnitySnapshotBuilder.GetObjectId(selected) : "";
|
||||
var sessionId = NormalizedSyncSessionId();
|
||||
var session = BuildSyncSession(now);
|
||||
var timelineObjectId = string.IsNullOrWhiteSpace(unityTimelineObjectId) ? selectedId : unityTimelineObjectId;
|
||||
var cinemachineObjectId = string.IsNullOrWhiteSpace(unityCinemachineObjectId) ? selectedId : unityCinemachineObjectId;
|
||||
var bindingId = StableId("timeline", sessionId, timelineObjectId, blenderSceneName, blenderActionName);
|
||||
var binding = new BrokkrSyncTimelineBinding
|
||||
{
|
||||
bindingId = bindingId,
|
||||
sessionId = sessionId,
|
||||
displayName = string.IsNullOrWhiteSpace(blenderActionName) ? "Timeline Sync" : blenderActionName,
|
||||
unityTimelineObjectId = timelineObjectId,
|
||||
unityCinemachineObjectId = cinemachineObjectId,
|
||||
blenderSceneName = blenderSceneName,
|
||||
blenderActionName = blenderActionName,
|
||||
clockAuthority = "blender",
|
||||
frameRate = syncTimelineFrameRate,
|
||||
syncFrame = syncTimelineFrame,
|
||||
syncCamera = syncCinemachineCamera,
|
||||
enabled = syncTimelineFrame || syncCinemachineCamera,
|
||||
updatedAt = now
|
||||
};
|
||||
|
||||
mirror.PublishSyncSessionAsync(session).GetAwaiter().GetResult();
|
||||
mirror.PublishTimelineBindingAsync(binding).GetAwaiter().GetResult();
|
||||
PublishSyncVar(bindingId, "timeline-frame", "Timeline Frame", "Timeline.time", "scene.frame_current", syncTimelineFrame, "linear", now);
|
||||
PublishSyncVar(bindingId, "cinemachine-virtual-camera", "Cinemachine Camera", "CinemachineVirtualCamera", "camera", syncCinemachineCamera, "linear", now);
|
||||
SetStatus($"Published Brokkr timeline sync binding: {binding.displayName}", MessageType.Info);
|
||||
}
|
||||
catch (Exception error)
|
||||
{
|
||||
SetStatus(error.Message, MessageType.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private BrokkrSyncSession BuildSyncSession(string observedAt)
|
||||
{
|
||||
return new BrokkrSyncSession
|
||||
{
|
||||
sessionId = NormalizedSyncSessionId(),
|
||||
displayName = string.IsNullOrWhiteSpace(syncDisplayName) ? "Brokkr Editor Sync" : syncDisplayName,
|
||||
mode = "manual",
|
||||
enabled = true,
|
||||
createdAt = observedAt,
|
||||
updatedAt = observedAt
|
||||
};
|
||||
}
|
||||
|
||||
private void PublishSyncVar(
|
||||
string bindingId,
|
||||
string kind,
|
||||
string displayName,
|
||||
string unityPropertyPath,
|
||||
string blenderPropertyPath,
|
||||
bool enabled,
|
||||
string interpolation,
|
||||
string updatedAt)
|
||||
{
|
||||
var syncVar = new BrokkrSyncVar
|
||||
{
|
||||
syncVarId = StableId("var", NormalizedSyncSessionId(), bindingId, kind),
|
||||
sessionId = NormalizedSyncSessionId(),
|
||||
bindingId = bindingId,
|
||||
displayName = displayName,
|
||||
kind = kind,
|
||||
unityPropertyPath = unityPropertyPath,
|
||||
blenderPropertyPath = blenderPropertyPath,
|
||||
authority = kind.StartsWith("timeline", StringComparison.Ordinal) ? "blender-to-unity" : "unity-to-blender",
|
||||
enabled = enabled,
|
||||
interpolation = interpolation,
|
||||
updatedAt = updatedAt
|
||||
};
|
||||
mirror.PublishSyncVarAsync(syncVar).GetAwaiter().GetResult();
|
||||
}
|
||||
|
||||
private static string BuildTransformPath(Transform transform)
|
||||
{
|
||||
var path = transform.name;
|
||||
while (transform.parent != null)
|
||||
{
|
||||
transform = transform.parent;
|
||||
path = $"{transform.name}/{path}";
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
private static string StableId(params string[] parts)
|
||||
{
|
||||
return string.Join(":", parts).Replace(" ", "_").Replace("/", "_").Replace("\\", "_");
|
||||
}
|
||||
|
||||
private string NormalizedSyncSessionId()
|
||||
{
|
||||
return string.IsNullOrWhiteSpace(syncSessionId) ? "default" : syncSessionId;
|
||||
}
|
||||
|
||||
private void OnEditorSignal()
|
||||
{
|
||||
if (autoPublish)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,94 @@
|
|||
using System;
|
||||
using GameCult.Caching;
|
||||
using MessagePack;
|
||||
|
||||
namespace GameCult.Brokkr
|
||||
{
|
||||
[CultDocument("brokkr.sync.session", "brokkr.sync.session.v0")]
|
||||
[MessagePackObject]
|
||||
[Serializable]
|
||||
public sealed class BrokkrSyncSession
|
||||
{
|
||||
[Key(0)] public string schema = "brokkr.sync.session.v0";
|
||||
[Key(1)] public string sessionId = "";
|
||||
[Key(2)] public string displayName = "";
|
||||
[Key(3)] public string owner = "brokkr.creative_tool_broker";
|
||||
[Key(4)] public string unityProviderId = "brokkr.unity_editor";
|
||||
[Key(5)] public string blenderProviderId = "brokkr.blender_editor";
|
||||
[Key(6)] public string mode = "manual";
|
||||
[Key(7)] public bool enabled;
|
||||
[Key(8)] public string createdAt = "";
|
||||
[Key(9)] public string updatedAt = "";
|
||||
}
|
||||
|
||||
[CultDocument("brokkr.sync.object_binding", "brokkr.sync.object_binding.v0")]
|
||||
[MessagePackObject]
|
||||
[Serializable]
|
||||
public sealed class BrokkrSyncObjectBinding
|
||||
{
|
||||
[Key(0)] public string schema = "brokkr.sync.object_binding.v0";
|
||||
[Key(1)] public string bindingId = "";
|
||||
[Key(2)] public string sessionId = "";
|
||||
[Key(3)] public string displayName = "";
|
||||
[Key(4)] public string unityObjectId = "";
|
||||
[Key(5)] public string unityPath = "";
|
||||
[Key(6)] public string blenderObjectName = "";
|
||||
[Key(7)] public string blenderCollectionName = "";
|
||||
[Key(8)] public bool enabled;
|
||||
[Key(9)] public string authority = "unity-to-blender";
|
||||
[Key(10)] public string updatedAt = "";
|
||||
}
|
||||
|
||||
[CultDocument("brokkr.sync.var", "brokkr.sync.var.v0")]
|
||||
[MessagePackObject]
|
||||
[Serializable]
|
||||
public sealed class BrokkrSyncVar
|
||||
{
|
||||
[Key(0)] public string schema = "brokkr.sync.var.v0";
|
||||
[Key(1)] public string syncVarId = "";
|
||||
[Key(2)] public string sessionId = "";
|
||||
[Key(3)] public string bindingId = "";
|
||||
[Key(4)] public string displayName = "";
|
||||
[Key(5)] public string kind = "";
|
||||
[Key(6)] public string unityPropertyPath = "";
|
||||
[Key(7)] public string blenderPropertyPath = "";
|
||||
[Key(8)] public string authority = "unity-to-blender";
|
||||
[Key(9)] public bool enabled;
|
||||
[Key(10)] public string interpolation = "step";
|
||||
[Key(11)] public string updatedAt = "";
|
||||
}
|
||||
|
||||
[CultDocument("brokkr.sync.timeline_binding", "brokkr.sync.timeline_binding.v0")]
|
||||
[MessagePackObject]
|
||||
[Serializable]
|
||||
public sealed class BrokkrSyncTimelineBinding
|
||||
{
|
||||
[Key(0)] public string schema = "brokkr.sync.timeline_binding.v0";
|
||||
[Key(1)] public string bindingId = "";
|
||||
[Key(2)] public string sessionId = "";
|
||||
[Key(3)] public string displayName = "";
|
||||
[Key(4)] public string unityTimelineObjectId = "";
|
||||
[Key(5)] public string unityCinemachineObjectId = "";
|
||||
[Key(6)] public string blenderSceneName = "";
|
||||
[Key(7)] public string blenderActionName = "";
|
||||
[Key(8)] public string clockAuthority = "blender";
|
||||
[Key(9)] public float frameRate = 24.0f;
|
||||
[Key(10)] public bool syncFrame;
|
||||
[Key(11)] public bool syncCamera;
|
||||
[Key(12)] public bool enabled;
|
||||
[Key(13)] public string updatedAt = "";
|
||||
}
|
||||
|
||||
[CultDocument("brokkr.sync.receipt", "brokkr.sync.receipt.v0")]
|
||||
[MessagePackObject]
|
||||
[Serializable]
|
||||
public sealed class BrokkrSyncReceipt
|
||||
{
|
||||
[Key(0)] public string schema = "brokkr.sync.receipt.v0";
|
||||
[Key(1)] public string receiptId = "";
|
||||
[Key(2)] public string sessionId = "";
|
||||
[Key(3)] public string status = "";
|
||||
[Key(4)] public string message = "";
|
||||
[Key(5)] public string observedAt = "";
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 8f6d086fce714afab48d3f29eec53901
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -33,12 +33,21 @@ try {
|
|||
Assert-Contains $providerText '"kind": "cultmesh"' "provider advertisement"
|
||||
Assert-Contains $providerText "brokkr.unity.host_snapshot.v0" "provider advertisement"
|
||||
Assert-Contains $providerText "brokkr.unity.command_intent.v0" "provider advertisement"
|
||||
Assert-Contains $providerText "brokkr.sync.var.v0" "provider advertisement"
|
||||
Assert-Contains $providerText "cinemachine-virtual-camera" "provider advertisement"
|
||||
foreach ($transport in $providerJson.transports) {
|
||||
if ($transport.kind -ne "cultmesh") {
|
||||
throw "Unexpected provider transport kind: $($transport.kind)"
|
||||
}
|
||||
}
|
||||
|
||||
$syncContract = cargo run -p brokkr-daemon -- sync-contract
|
||||
Assert-NativeSuccess "cargo sync-contract smoke"
|
||||
$syncContractText = ($syncContract | Out-String)
|
||||
Assert-Contains $syncContractText "brokkr.sync.timeline_binding.v0" "sync contract"
|
||||
Assert-Contains $syncContractText "timeline-frame" "sync contract"
|
||||
Assert-Contains $syncContractText "cinemachine-virtual-camera" "sync contract"
|
||||
|
||||
$pluginRoot = Join-Path (Get-Location) "surfaces\unity\Packages\com.gamecult.brokkr\Plugins\CultMesh"
|
||||
$requiredDlls = @(
|
||||
"GameCult.Caching.dll",
|
||||
|
|
|
|||
Loading…
Reference in a new issue