Add parallel typed ship authoring and Blender LineArt capture
This commit is contained in:
parent
4b594e116c
commit
42eb5214ce
8 changed files with 636 additions and 1 deletions
|
|
@ -36,8 +36,9 @@ public static class Program
|
|||
case "targeting-catalog": return TargetingCatalog(args.Contains("apply"));
|
||||
case "targeting-catalog-6c": return TargetingCatalog6c(args.Contains("apply"));
|
||||
case "targeting-catalog-6d": return TargetingCatalog6d(args.Contains("apply"));
|
||||
case "ship-authoring": return ShipAuthoringCommands.Run(args.Skip(1).ToArray());
|
||||
default:
|
||||
Console.WriteLine("commands: census, factions, station-fit, hardpoint-fit, loadout [seed], save, settings, settings-dump, dangling [clear <Type.Member>]... [apply], shield-migrate [apply], brownout-migrate [apply], roles-migrate [apply], firing-arc-migrate [apply], targeting-catalog [apply], targeting-catalog-6c [apply], targeting-catalog-6d [apply]");
|
||||
Console.WriteLine("commands: census, factions, station-fit, hardpoint-fit, loadout [seed], save, settings, settings-dump, dangling [clear <Type.Member>]... [apply], shield-migrate [apply], brownout-migrate [apply], roles-migrate [apply], firing-arc-migrate [apply], targeting-catalog [apply], targeting-catalog-6c [apply], targeting-catalog-6d [apply], ship-authoring create|inspect|validate");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
62
tools/AetherDb/ShipAuthoringCommands.cs
Normal file
62
tools/AetherDb/ShipAuthoringCommands.cs
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
// Uses the existing database executable; mod authoring does not earn another binary target.
|
||||
public static class ShipAuthoringCommands
|
||||
{
|
||||
public static int Run(string[] args)
|
||||
{
|
||||
if (args.Length == 0)
|
||||
{
|
||||
Console.Error.WriteLine("ship-authoring create <ship.cc> <stable-id> <name> | inspect <ship.cc> | validate <ship.cc>");
|
||||
return 1;
|
||||
}
|
||||
try
|
||||
{
|
||||
if (args[0] == "inspect" && args.Length == 2)
|
||||
{
|
||||
using var cache = ShipAuthoringStore.Open(args[1]);
|
||||
var records = cache.GetAll<ShipAuthoring>().ToArray();
|
||||
if (records.Length != 1) throw new InvalidOperationException($"Expected one ship, found {records.Length}.");
|
||||
var ship = records[0];
|
||||
Console.WriteLine($"{ship.Id}: {ship.Hull?.Name}, {ship.Hull?.Hardpoints?.Count ?? 0} hardpoints, {ship.SchematicLines?.Count ?? 0} lines, {ship.SchematicLines?.Sum(line => line.Points?.Length / 3 ?? 0) ?? 0} points");
|
||||
return 0;
|
||||
}
|
||||
if (args[0] == "validate" && args.Length == 2)
|
||||
{
|
||||
var ship = ShipAuthoringStore.Read(args[1]);
|
||||
Console.WriteLine($"{ship.Id}: {ship.Hull.Name}, {ship.Hull.Hardpoints.Count} hardpoints, {ship.SchematicLines.Count} lines");
|
||||
return 0;
|
||||
}
|
||||
if (args[0] == "create" && args.Length == 4)
|
||||
{
|
||||
var path = Path.GetFullPath(args[1]);
|
||||
if (File.Exists(path)) throw new InvalidOperationException($"Refusing to replace {path}");
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(path));
|
||||
var ship = new ShipAuthoring
|
||||
{
|
||||
Id = args[2],
|
||||
Hull = new HullData { Name = args[3], Shape = new Shape() },
|
||||
ModelAsset = "ship.glb",
|
||||
Anchors = new List<ShipAnchor>()
|
||||
};
|
||||
using (var cache = ShipAuthoringStore.Open(path, writable: true))
|
||||
{
|
||||
cache.Upsert(ship);
|
||||
cache.FlushAsync().Wait();
|
||||
}
|
||||
Console.WriteLine($"Created draft {path}; fill its model bindings and schematic in Blender.");
|
||||
return 0;
|
||||
}
|
||||
Console.Error.WriteLine("ship-authoring create <ship.cc> <stable-id> <name> | inspect <ship.cc> | validate <ship.cc>");
|
||||
return 1;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.Error.WriteLine(ex.Message);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
87
tools/blender/aetheria_ships/__init__.py
Normal file
87
tools/blender/aetheria_ships/__init__.py
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
"""Aetheria ship authoring controls in Brokkr's Blender sidebar."""
|
||||
|
||||
bl_info = {
|
||||
"name": "Aetheria Ships for Brokkr",
|
||||
"author": "GameCult",
|
||||
"version": (0, 1, 0),
|
||||
"blender": (4, 3, 0),
|
||||
"location": "View3D > Sidebar > Brokkr > Aetheria Ship",
|
||||
"description": "Write Grease Pencil ship lines into a typed Aetheria .cc ship record",
|
||||
"category": "Object",
|
||||
}
|
||||
|
||||
import bpy
|
||||
|
||||
from .ship_cc import capture_grease_pencil, replace_lines
|
||||
|
||||
|
||||
def _brokkr_cultlib(context):
|
||||
brokkr = context.preferences.addons.get("brokkr_bridge")
|
||||
if brokkr is None:
|
||||
raise RuntimeError("Enable Brokkr before using Aetheria Ships")
|
||||
return brokkr.preferences.cultlib_py_src
|
||||
|
||||
|
||||
class AETHERIA_OT_capture_ship_lines(bpy.types.Operator):
|
||||
bl_idname = "aetheria.capture_ship_lines"
|
||||
bl_label = "Capture Ship Lines"
|
||||
bl_description = "Replace only the line slot in the selected typed ship .cc record"
|
||||
bl_options = {"REGISTER"}
|
||||
|
||||
def execute(self, context):
|
||||
try:
|
||||
obj = context.active_object
|
||||
if obj is None:
|
||||
raise ValueError("Select the ship's Grease Pencil LineArt object")
|
||||
if not context.scene.aetheria_ship_cc_path:
|
||||
raise ValueError("Choose an existing ship authoring .cc file")
|
||||
path = bpy.path.abspath(context.scene.aetheria_ship_cc_path)
|
||||
cultlib = _brokkr_cultlib(context)
|
||||
lines = capture_grease_pencil(
|
||||
obj, context.evaluated_depsgraph_get(), context.scene.frame_current,
|
||||
evaluated=context.scene.aetheria_capture_evaluated_lines,
|
||||
)
|
||||
count = replace_lines(path, cultlib, lines)
|
||||
self.report({"INFO"}, f"Captured {count} lines into {path}")
|
||||
return {"FINISHED"}
|
||||
except (OSError, ValueError, RuntimeError, ImportError) as exc:
|
||||
self.report({"ERROR"}, str(exc))
|
||||
return {"CANCELLED"}
|
||||
|
||||
|
||||
class AETHERIA_PT_ship(bpy.types.Panel):
|
||||
bl_label = "Aetheria Ship"
|
||||
bl_idname = "AETHERIA_PT_ship"
|
||||
bl_space_type = "VIEW_3D"
|
||||
bl_region_type = "UI"
|
||||
bl_category = "Brokkr"
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
layout.prop(context.scene, "aetheria_ship_cc_path")
|
||||
layout.prop(context.scene, "aetheria_capture_evaluated_lines")
|
||||
obj = context.active_object
|
||||
layout.label(text=f"Source: {obj.name if obj else '(none)'}")
|
||||
layout.operator("aetheria.capture_ship_lines", icon="GREASEPENCIL")
|
||||
|
||||
|
||||
classes = (AETHERIA_OT_capture_ship_lines, AETHERIA_PT_ship)
|
||||
|
||||
|
||||
def register():
|
||||
bpy.types.Scene.aetheria_ship_cc_path = bpy.props.StringProperty(
|
||||
name="Ship .cc", subtype="FILE_PATH", description="Existing typed ship authoring record"
|
||||
)
|
||||
bpy.types.Scene.aetheria_capture_evaluated_lines = bpy.props.BoolProperty(
|
||||
name="Evaluated LineArt", default=True,
|
||||
description="Capture the visible modifier result at the current frame",
|
||||
)
|
||||
for cls in classes:
|
||||
bpy.utils.register_class(cls)
|
||||
|
||||
|
||||
def unregister():
|
||||
for cls in reversed(classes):
|
||||
bpy.utils.unregister_class(cls)
|
||||
del bpy.types.Scene.aetheria_capture_evaluated_lines
|
||||
del bpy.types.Scene.aetheria_ship_cc_path
|
||||
93
tools/blender/aetheria_ships/ship_cc.py
Normal file
93
tools/blender/aetheria_ships/ship_cc.py
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
"""Aetheria's Blender-side view of one typed ShipAuthoring CultCache record.
|
||||
|
||||
The schema and authority live in Aetheria's C# ShipAuthoring type. This module
|
||||
preserves the C# schema catalog and all slots it does not edit. Brokkr supplies
|
||||
the Blender host and CultLib Python dependency path.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sys
|
||||
from dataclasses import replace
|
||||
from datetime import datetime, timezone
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
SCHEMA = "aetheria.ship_authoring"
|
||||
SCHEMATIC_LINES_SLOT = 4
|
||||
|
||||
|
||||
def _libraries(cultlib_packages: str):
|
||||
source = Path(cultlib_packages) / "cultcache-py" / "src"
|
||||
if source.exists() and str(source) not in sys.path:
|
||||
sys.path.insert(0, str(source))
|
||||
import cultcache_py # type: ignore
|
||||
import msgpack # type: ignore
|
||||
return cultcache_py, msgpack
|
||||
|
||||
|
||||
def read(path: str, cultlib_packages: str):
|
||||
cultcache, msgpack = _libraries(cultlib_packages)
|
||||
store = cultcache.SingleFileMessagePackBackingStore(path)
|
||||
envelopes = store.pull_all()
|
||||
ships = [envelope for envelope in envelopes if envelope.type == SCHEMA]
|
||||
if len(envelopes) != 1 or len(ships) != 1:
|
||||
raise ValueError(f"{path} must hold exactly one {SCHEMA} record")
|
||||
envelope = ships[0]
|
||||
body = msgpack.unpackb(envelope.payload, raw=False)
|
||||
if not isinstance(body, list) or len(body) < SCHEMATIC_LINES_SLOT + 1:
|
||||
raise ValueError(f"{path} has an incompatible {SCHEMA} payload")
|
||||
return store, envelope, body, msgpack
|
||||
|
||||
|
||||
def replace_lines(path: str, cultlib_packages: str, lines: list[list[Any]]) -> int:
|
||||
store, envelope, body, msgpack = read(path, cultlib_packages)
|
||||
if not lines:
|
||||
raise ValueError("No Grease Pencil strokes were captured; the ship record was not changed")
|
||||
body[SCHEMATIC_LINES_SLOT] = lines
|
||||
updated = replace(
|
||||
envelope,
|
||||
payload=msgpack.packb(body, use_bin_type=True),
|
||||
stored_at=datetime.now(timezone.utc).isoformat(),
|
||||
)
|
||||
store.push(updated)
|
||||
return len(lines)
|
||||
|
||||
|
||||
def capture_grease_pencil(obj: Any, depsgraph: Any, frame_number: int, *, evaluated: bool = True) -> list[list[Any]]:
|
||||
if obj.type != "GREASEPENCIL":
|
||||
raise ValueError(f"{obj.name} is not a Grease Pencil object")
|
||||
source = obj.evaluated_get(depsgraph) if evaluated else obj
|
||||
lines: list[list[Any]] = []
|
||||
for layer in source.data.layers:
|
||||
frames = [frame for frame in layer.frames if frame.frame_number <= frame_number]
|
||||
if not frames:
|
||||
continue
|
||||
frame = max(frames, key=lambda candidate: candidate.frame_number)
|
||||
for stroke in frame.drawing.strokes:
|
||||
if len(stroke.points) < 2:
|
||||
continue
|
||||
material = source.data.materials[stroke.material_index]
|
||||
rgba = (
|
||||
tuple(material.grease_pencil.color)
|
||||
if material and material.grease_pencil
|
||||
else tuple(material.diffuse_color) if material else (1.0, 1.0, 1.0, 1.0)
|
||||
)
|
||||
points: list[float] = []
|
||||
radii: list[float] = []
|
||||
opacities: list[float] = []
|
||||
for point in stroke.points:
|
||||
position = obj.matrix_world @ point.position
|
||||
points.extend(float(value) for value in position)
|
||||
radii.append(float(point.radius))
|
||||
opacities.append(float(point.opacity))
|
||||
lines.append([
|
||||
layer.name,
|
||||
material.name if material else "",
|
||||
points,
|
||||
radii,
|
||||
opacities,
|
||||
bool(stroke.cyclic),
|
||||
[float(value) for value in rgba],
|
||||
])
|
||||
return lines
|
||||
Loading…
Reference in a new issue